Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: David Goodger <goodger <at> python.org>
Subject: Re: Error handling with publish_doctree
Newsgroups: gmane.text.docutils.user
Date: Tuesday 5th February 2008 23:51:20 UTC (over 9 years ago)
[Stefan Seefeld]
> Hello,
> 
> I'm using the publish_doctree API to translate a ReST string into chunks 
> of HTML (and other formats) that I'm embedding into a bigger document.
> 
> I'm wondering about how to deal with errors. Right now, ReST syntax 
> errors result in HTML error messages embedded into the generated output. 
> I'd rather like to intercept the errors for post-processing, but I'm not 
> sure how.
 >
> I know the publish_doctree() call expects a settings_override dictionary 
> with entries for report_level, halt_level, and warning_stream. Are these 
> the values to customize ? (I tried a bit but couldn't get the desired 
> effect.)
> What's the best way to do what I want ? Is this documented somewhere ?

To turn all processing errors into exceptions that you can intercept:

overrides = {'halt_level': 2,  # warnings and up; adjust as necessary
              'traceback': True}
try:
     doctree = publish_doctree(..., settings_overrides=overrides)
except docutils.utils.SystemMessage, error:
     # deal with the exceptions here

Note that you'll only see the *first* exception that takes place.  There's
no 
way to continue processing once it has halted.

Hope this helps.

-- 
David Goodger <http://python.net/~goodger>
 
CD: 4ms