Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#101 closed defect (released)

Query parser throws raw strings as exceptions

Reported by: Richard Boulton Owned by: Olly Betts
Priority: normal Milestone:
Component: Library API Version: SVN trunk
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Operating System: All

Description

At line 131 of the query parser, the query parser throws an plain std::string as an exception. This should probably be wrapped in a subclass of Xapian::Error, so that applications can catch all Xapian errors using "catch Xapian::Error".

One particular problem this causes is with the SWIG bindings, which catch only Xapian::Error subclasses. As a result, the message from a queryparser error is thrown away, and replaced with "unknown error in Xapian".

Change History (6)

comment:1 by Olly Betts, 18 years ago

op_sys: LinuxAll
rep_platform: PCAll
Status: newassigned

Line 131 of queryparser/queryparser.cc

This is a hang over from when queryparser was just part of Omega. I meant to change this when the QueryParser API was overhauled, but obviously I didn't!

I guess it would be reasonable to fix this in 1.0.

comment:2 by Richard Boulton, 18 years ago

I've added a catch() to the SWIG bindings so that they report the error string, rather than "unknown error in Xapian" for these errors. I agree that this should be fixed for 1.0 (at which point this catch() clause could be removed).

comment:3 by Olly Betts, 18 years ago

I think we should anticipate how this will be fixed in 1.0 and make it so the exception string is something like:

"QueryParserError: " + str

instead of just:

str

That way user code in scripting languages won't need to change at all for this change in 1.0 (user C++ code will need to change slightly of course).

It would also be good to have a test for this in the smoketest for languages where it's possible (it probably isn't really for PHP4).

comment:4 by Olly Betts, 18 years ago

Actually, the exception thrown is "const char *", not "std::string" so your change doesn't make any difference - an excellent demonstration of why we really should add test cases wherever possible!

I've fixed this and added the "QueryParserError: " prefix, and added a testcase for both PHP4 (turns out it is possible) and PHP5.

Equivalent tests for other languages would still be nice though.

comment:5 by Olly Betts, 18 years ago

Resolution: fixed
Status: assignedclosed

Now fixed in SVN HEAD.

comment:6 by Olly Betts, 18 years ago

Operating System: All
Resolution: fixedreleased

Fixed in 1.0.0 release.

Note: See TracTickets for help on using tickets.