felixc / rexiv2

Rust library for read/write access to media-file metadata (Exif, XMP, and IPTC)
GNU General Public License v3.0
79 stars 17 forks source link

Supress warnings from gexiv2 #36

Closed ghost closed 4 years ago

ghost commented 4 years ago

Currently, rexiv2 prints warnings as they are printed from gexiv2. For example, parsing this corrupted image with code like this:

fn main() {
  match rexiv2::Metadata::new_from_path(<image>) {
    Ok(metadata) => { /* */ }
    Err(_) => { }
  };
}

prints:

** (process:78576): WARNING **: 00:08:31.935: Directory OlympusCs, entry 0x0101: Strip 0 is outside of the data area; ignored.

** (process:78576): WARNING **: 00:08:31.939: Invalid JPEG preview image.

If possible, there should be a way to silence these warnings, or maybe have them returned as an error in a Result.

felixc commented 4 years ago

Good idea!

The low-level mechanism for this already exists in the gexiv2-sys wrapper, in the form of the various gexiv2_log_* functions: https://github.com/felixc/gexiv2-sys/blob/11e04f4cf073de591e99c65cee1896b99a928962/src/lib.rs#L205-L211

It should be possible to build something like what you're looking for on top of these. I don't have an API in mind right now, though; so I'm very open to ideas here!

felixc commented 4 years ago

Fixed in https://github.com/felixc/rexiv2/commit/1fadb5f37d248cec2640f20a33ac5a8bb208d62c which landed https://github.com/felixc/rexiv2/pull/37 — thank you @t1ra for this improvement!