propagation of error messages in matplotlib

Slight problem: it might now be a little bit more

    > difficult to include the name of the file which could not
    > be opened in the error message. The IOError exception
    > will probably only have "permission denied" associated
    > with it.

Looks OK, at least on linux

file('/sbin/ldconfig', 'w')

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 13] Permission denied: '/sbin/ldconfig'

Hello,

    > Slight problem: it might now be a little bit more
    > difficult to include the name of the file which could not
    > be opened in the error message. The IOError exception
    > will probably only have "permission denied" associated
    > with it.

Looks OK, at least on linux

>>> file('/sbin/ldconfig', 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 13] Permission denied: '/sbin/ldconfig'

But sometimes it doesn't give the file name:

    >>> from matplotlib.matlab import *
    >>> plot([1,2,3],[2,3,1])
    [<matplotlib.lines.Line2D instance at 0x41ef774c>]
    >>> savefig("/forbidden.png")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File ".../matlab.py", line 1009, in savefig
        manager.canvas.print_figure(*args, **kwargs)
      File ".../backends/backend_gtkagg.py", line 69, in print_figure
        agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
      File ".../backends/backend_agg.py", line 379, in print_figure
        self.renderer._renderer.write_png(str(filename))
    RuntimeError: could not open file

I did not investigate what happens here, but if there is an easy way to
get the file name into the exception we should probably use it.

All the best,
Jochen

···

On Fri, Nov 19, 2004 at 10:33:43AM -0600, John Hunter wrote:
--

For an IOError the exception attribute 'filename' is set to the
filename. With your example above self.renderer._renderer.write_png(str
(filename)) is Agg C++ extension code
The line
fp = fopen(file_name, "wb");
could be changed to something like
if ((fp = fopen(file_name, "wb")) == NULL)
     throw Py::IOError("could not open file", filename);

Does this look right John?

Steve

···

On Wed, 2004-11-24 at 12:06 +0000, Jochen Voss wrote:

Hello,

On Fri, Nov 19, 2004 at 10:33:43AM -0600, John Hunter wrote:

> > Slight problem: it might now be a little bit more
> > difficult to include the name of the file which could not
> > be opened in the error message. The IOError exception
> > will probably only have "permission denied" associated
> > with it.
>
> Looks OK, at least on linux
>
>
> >>> file('/sbin/ldconfig', 'w')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> IOError: [Errno 13] Permission denied: '/sbin/ldconfig'

But sometimes it doesn't give the file name:

    >>> from matplotlib.matlab import *
    >>> plot([1,2,3],[2,3,1])
    [<matplotlib.lines.Line2D instance at 0x41ef774c>]
    >>> savefig("/forbidden.png")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File ".../matlab.py", line 1009, in savefig
        manager.canvas.print_figure(*args, **kwargs)
      File ".../backends/backend_gtkagg.py", line 69, in print_figure
        agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
      File ".../backends/backend_agg.py", line 379, in print_figure
        self.renderer._renderer.write_png(str(filename))
    RuntimeError: could not open file

I did not investigate what happens here, but if there is an easy way to
get the file name into the exception we should probably use it.

All the best,
Jochen