switching to PS/SVG backends

I tried this calling the SVG backend directly and by

    > switching to the SVG backend from the GTK backend and it
    > works OK.

This gets back to our previous unresolved discussion on error handling
in the image backends. I think the way it is done now is a historical
accident. In the olden days, pre matplotlib-0.50, there was no
ability to switch backends, or to use an image backend within a GUI
(eg gtkcairo, gtkagg). So the image backends were free-standing and
their error handling didn't have much impact outside their own scope.
Now they clearly do.

The second design problem was that I preferred simple error messages
rather than exceptions with tracebacks. This grew out of my
experience with users of my GUIs who basically will not read a
traceback - they appear to have blinders on. However, they will read
a simple message like

  Could not save file blah, blah, blah.

But as we are seeing, this approach (simple message, SystemExit)
doesn't scale well and isn't appropriate when GUIs are calling image
backends.

I suggest we rework the image backends to not define an error message
function at all, but simply to import and reuse the one from
backend_bases. This will make it easier to change the policy in a
single place. Secondly, an image backend should never call this
function, it should be reserved for the matlab interface simply to
insure a consistent interface between the various backends. Thirdly,
the image backends should verbose.report/report_error where
appropriate, and raise when indicated. GUI backends can catch these
exceptions and handle them how they want.

In the case at hand, it might be sensible for backend ps to catch an
IO Error, report to verbose report_error, and then rethrow the error
with the message. Something like

try : save_ps(fname)
except IOError, msg:
   verbose.report_error('Backend PS failed to save %s'%fname)
   raise IOError(msg)

Thoughts?

JDH

Hello John,

I suggest we rework the image backends to not define an error message
function at all, but simply to import and reuse the one from
backend_bases. This will make it easier to change the policy in a
single place. Secondly, an image backend should never call this
function, it should be reserved for the matlab interface simply to
insure a consistent interface between the various backends.

Sorry, I am still not clear about this function. What is its purpose?
When will it be called?

Thirdly, the image backends should verbose.report/report_error where
appropriate, and raise when indicated. GUI backends can catch these
exceptions and handle them how they want.

This sounds fine for me.

All the best,
Jochen

···

On Thu, Nov 18, 2004 at 10:24:57AM -0600, John Hunter wrote:
--

John Hunter schrieb:

try : save_ps(fname)
except IOError, msg:
   verbose.report_error('Backend PS failed to save %s'%fname)
   raise IOError(msg)

Just 'raise' is enough, python by default will re-raise the original exception untouched.

I'll leave this discussion to you guys, I don't know the matplotlib code enough to contribute anything really useful. My only point is that reusing SystemExit for other purposes, with additional information encoded in the message, is IMHO a bad idea. There's a reason why exceptions make up a class hierarchy: this allows you to use classes for the flow control mechanisms, leaving the string messages simply as additional information mainly for the user. Since these messages are potentially locale-sensitive, and can change over time (spelling, capitalization, etc), it's just not a good idea to base code behaviour on them.

Cheers,

f