[redland-dev] parse_into_model on bad RDF

Dave Beckett dave.beckett at bristol.ac.uk
Wed Feb 2 10:32:25 GMT 2005


On Fri, 14 Jan 2005 07:10:26 -0500, Christopher Schmidt <crschmidt at crschmidt.net> wrote:

> The following python:
> 
> import RDF
> 
> m = RDF.Model()
> p = RDF.Parser()
> p.parse_into_model(m, RDF.Uri("http://dannyayers.com/feed/rdf"))
> 
> causes an "unhandled error during garbage collection", after which 
> Python bails out with an "aborted", after printing:
> 
> Exception RDF.RedlandError: <RDF.RedlandError instance at 0x403344cc> in 
> 'garbage collection' ignored
> 
> It seems that it gets out of the Redland stuff before it bails, but it's 
> not something I can catch with a try/except.
> 
> The feed above is an invalid feed, which may be the problem?
> 
> Not really a major concern, but I like to eliminate things which force 
> Python to bail out, since they cause julie to collapse.

I've looked into this and it is caused by this set of events

Python class parser method parse_into_model
  calls
C function librdf_parser_parse_into_model
  Gets a parse error and calls
Python function message_handler (in RDF.py)
  which then does
raise RedlandError("Syntax error of some sort")

at which point things go screwy inside Python as it doesn't actually
raise the error message then but ignores it till the main program
ends.  Why?  No idea.

The quick fix is to remove the "raise RedlandError(message)" from
RDF.py and record the error message in another variable, then look at
it after parse_into_model returns to see if there was an error.

I'm not quite sure what's the best solution - somehow convince SWIG
to do exception handlings for me or to make a new error returning
solution and ditch the raise, or hand-code some fix another way.

Mostly the only time you care about the message from errors in
parsing but it's not the only case.  Most constructors could fail,
anything reading from a stream and there are always chances of rarer
errors needing to be reported.

Dave


More information about the redland-dev mailing list