more detailed error messages

60 views
Skip to first unread message

Karl Lehenbauer

unread,
Mar 22, 2015, 9:24:17 AM3/22/15
to cpp-dri...@lists.datastax.com
Error messages returned from cass_future_error_message(), even in response to a complicated statement, are pretty terse and nonspecific, such as "syntax error" or "query error", yet the cqlsh error messages are considerably better.

I send "select * from table where noncolumn = 'bar'" through calls to cpp-driver and I get back "Invalid query" but when I type that into cqlsh I get

InvalidRequest: code=2200 [Invalid query] message="Undefined name foo in where clause ('foo = 'bar'')"

...which is way better. I know cqlsh uses the thrift API and I haven't examined it to see what it's doing but is there a way through cpp-driver to get the "Undefined name foo in where clause ('foo = 'bar'')" and if not, could one be added? I note also that nothing comes through the logging callbacks on this even at the debug logging level.

Michael Fero

unread,
Mar 22, 2015, 10:15:34 AM3/22/15
to cpp-dri...@lists.datastax.com
Karl,

Using the following keyspaces and tables:

CREATE KEYSPACE examples WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};
CREATE TABLE examples.detailed_error_message (key text, PRIMARY KEY (key));

... you can get a more detailed error message from the future using the example code below:

CassError rc = CASS_OK;
CassStatement* statement = NULL;
CassFuture* future = NULL;
CassString query = cass_string_init("SELECT * FROM examples.detailed_error_message WHERE foo = 'bar'");

statement = cass_statement_new(query, 0);
future = cass_session_execute(session, statement);
cass_future_wait(future);

/* Retrieve error message from future and display */
rc = cass_future_error_code(future);
if(rc != CASS_OK) {
CassString message = cass_future_error_message(future);
fprintf(stderr, "Error: %.*s\n", (int) message.length, message.data);
}

cass_future_free(future);
cass_statement_free(statement);

This code with your query statement would yield the following error message:

Error: Undefined name foo in where clause ('foo = 'bar'')

~Fero

Karl Lehenbauer

unread,
Mar 22, 2015, 11:17:29 AM3/22/15
to cpp-dri...@lists.datastax.com
On Sunday, March 22, 2015 at 9:15:34 AM UTC-5, Michael Fero wrote:

> CassString message = cass_future_error_message(future);

Fero, that's perfect! I had overlooked cass_future_error_message() and had only been using cass_error_desc() on the CassError value.

Now in casstcl everywhere it examines a future it uses cass_future_error_message(), changing, for instance "Invalid query" into, "Invalid query: No keyspace has been specified. USE a keyspace, or explicitly specify keyspace.tablename"

Huge thanks!

Reply all
Reply to author
Forward
0 new messages