[Xapian-discuss] Why is a "DocNotFoundError" when deleting a document a Fatal error in php?

Arjen van der Meijden acmmailing at tweakers.net
Fri Oct 28 11:35:28 BST 2005


Well, I've tried a trivial "fix" and that seems to work (of course only 
if all Xapian::RuntimeErrors are to be PHP Warnings). I came up with 
that by just grepping in the swig-code for SWIG_exception and such things.

I haven't tried the entire maintainer-process, so I just replaced a few 
hundred lines in php/xapian_wrap.cc

OMSWIG_exception(SWIG_RuntimeError, e);
for
zend_error(E_WARNING, const_cast<char *>(((e).get_type() + ": " + 
(e).get_msg()).c_str()));

If I understand things correctly it should work to add this to the 
php/util.i(.in)

%exception {
     try {
         $function
     } catch (const Xapian::InvalidArgumentError &e) {
         OMSWIG_exception(SWIG_ValueError, e);
     } catch (const Xapian::RangeError &e) {
         OMSWIG_exception(SWIG_IndexError, e);
     } catch (const Xapian::DatabaseError &e) {
         OMSWIG_exception(SWIG_IOError, e);
     } catch (const Xapian::NetworkError &e) {
         OMSWIG_exception(SWIG_IOError, e);
     } catch (const Xapian::RuntimeError &e) {
         zend_error(E_WARNING, const_cast<char *>(((e).get_type() + ": " 
+ (e).get_msg()).c_str()));
     } catch (const Xapian::Error &e) {
         OMSWIG_exception(SWIG_UnknownError, e);
     } catch (...) {
         SWIG_exception(SWIG_UnknownError, "unknown error in Xapian");
     }
}

This'll yield warnings instead of errors in php. But it of course 
doesn't stop processing anymore, so the Database_get_document will 
return a Document-resource instead of something like false or null, that 
may also need a fix but I haven't checked how to do that.

Best regards,

Arjen

Olly Betts wrote:
> On Fri, Oct 28, 2005 at 10:56:59AM +0200, Arjen van der Meijden wrote:
>> So if Xapian::RuntimeError should not be fatal in php (which I think it 
>> shouldn't)
> 
> Indeed - the current handling of exceptions by the PHP bindings is
> unhelpful.  The documentation notes that this needs fixing.
> 
>> it probably needs to be adjusted to do something like 
>> zend_error(E_WARNING, someMessage); instead of Swig's own exception 
>> handler (or the swig-handler should be reworked to have RuntimeErrors 
>> not be fatal).
> 
> You seem to understand what's going on with SWIG and PHP better than I
> do.  Are you able to work up a patch?
> 
> Cheers,
>     Olly
> 



More information about the Xapian-discuss mailing list