Investigate the ability to catch stderr from libexiv2 in pyexiv

Bug #507620 reported by simonm
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyexiv2
Fix Released
Wishlist
Olivier Tilloy

Bug Description

Email conversation below. Basically it would be a nice feature to be able to catch errors in a python exception to report on which file has a the error. When traversing large amounts of files the errors sent to stdout do not state which file has the error.

Simon Morley a écrit :
> > Hi Oliver,
> >
> > I've just started using pyexiv2 and from what I've seen it looks very
> > good. However can you tell me how to suppress warnings?
> > Also is it possible to catch errors higher up and deal with them? The
> > errors don't seem to report what file has the error which is annoying.

The warnings and errors are issued on the standard error stream by
libexiv2 itself, upon which pyexiv2 is built.
A quick solution to drop them is to simply redirect stderr to /dev/null.
I'm not sure there is much that can be done to in pyexiv2 to
ignore/catch those messages unless an exception is thrown by libexiv2
(in which case it's easy to translate it into a python exception), but
it's worth investigating.

Related branches

Revision history for this message
Olivier Tilloy (osomon) wrote :

Note: the errors mentioned by Simon are the "Error" and "Warning" messages output on stderr while reading an image file if libexiv2 fails to parse some metadata, e.g.:

Error: Directory Image: Next pointer is out of bounds; ignored.
Warning: Directory Image, entry 0x0000 has unknown Exif (TIFF) type 0; setting type size 1.
Error: Directory Unknown with 54333 entries considered invalid; not read.
Warning: Directory Thumbnail, entry 0x0201: Data area exceeds data buffer, ignoring it.
Error: Directory Unknown with 8f64 entries considered invalid; not read.
Warning: Directory Thumbnail, entry 0x0201: Data area exceeds data buffer, ignoring it.
Error: Directory Unknown with 53c1 entries considered invalid; not read.
Warning: Directory Thumbnail, entry 0x0201: Data area exceeds data buffer, ignoring it.
Error: Directory Unknown with 42dd entries considered invalid; not read.
Warning: Directory Thumbnail, entry 0x0201: Data area exceeds data buffer, ignoring it.
Error: Directory Unknown with 7c8 entries considered invalid; not read.
Warning: Directory Thumbnail, entry 0x0201: Data area exceeds data buffer, ignoring it.
Error: Directory Canon with 1800 entries considered invalid; not read.

Changed in pyexiv2:
importance: Undecided → Wishlist
status: New → Triaged
dansamara (dan-samara)
Changed in pyexiv2:
status: Triaged → Confirmed
Revision history for this message
Olivier Tilloy (osomon) wrote :

Redirecting std::cerr can be achieved using its rdbuf(…) method (see http://www.cplusplus.com/reference/iostream/ios/rdbuf/).
Parsing the messages may even be used to raise corresponding python exceptions, although I’m not sure that would be of any use (other than force the programmer to enclose the read/write calls in try… except… blocks).

Olivier Tilloy (osomon)
Changed in pyexiv2:
assignee: nobody → Olivier Tilloy (osomon)
status: Confirmed → In Progress
Revision history for this message
Olivier Tilloy (osomon) wrote :

Fixed in trunk (revision 325).
All the warnings and error messages that libexiv2 writes to std::cerr are now swallowed.
Note that interestingly this doesn’t affect python’s sys.stderr.

Changed in pyexiv2:
status: In Progress → Fix Committed
Olivier Tilloy (osomon)
Changed in pyexiv2:
milestone: none → 0.3
Olivier Tilloy (osomon)
Changed in pyexiv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.