diff --git a/src/error.rs b/src/error.rs index 76fe977..92839a9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,6 +42,10 @@ pub enum Error { /// whose meanings are defined as "unknown". Such a blank value /// should be treated the same as the absence of the field. BlankValue(&'static str), + /// Field values or image data are too big to encode. + TooBig(&'static str), + /// The field type is not supported and cannnot be encoded. + NotSupported(&'static str), } impl From for Error { @@ -57,6 +61,8 @@ impl fmt::Display for Error { Error::Io(ref err) => err.fmt(f), Error::NotFound(msg) => f.write_str(msg), Error::BlankValue(msg) => f.write_str(msg), + Error::TooBig(msg) => f.write_str(msg), + Error::NotSupported(msg) => f.write_str(msg), } } } @@ -68,6 +74,8 @@ impl error::Error for Error { Error::Io(ref err) => err.description(), Error::NotFound(msg) => msg, Error::BlankValue(msg) => msg, + Error::TooBig(msg) => msg, + Error::NotSupported(msg) => msg, } } @@ -77,6 +85,8 @@ impl error::Error for Error { Error::Io(ref err) => Some(err), Error::NotFound(_) => None, Error::BlankValue(_) => None, + Error::TooBig(_) => None, + Error::NotSupported(_) => None, } } } diff --git a/src/lib.rs b/src/lib.rs index ab2c0db..2c55d16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,7 @@ //! //! Major changes between 0.2.3 and 0.3 are listed below. //! +//! * Enum Error has two new variants: TooBig and NotSupported. pub use error::Error; pub use jpeg::get_exif_attr as get_exif_attr_from_jpeg; diff --git a/src/writer.rs b/src/writer.rs index ad12f40..f2b7c7b 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -155,10 +155,6 @@ impl<'a> Writer<'a> { /// /// The write position of `w` must be set to zero before calling /// this method. - /// - /// A new `exif::Error` variant will be introduced in the next - /// API-version bump to return write errors. `Error::InvalidFormat` - /// is used until then. pub fn write(&mut self, w: &mut W, little_endian: bool) -> Result<(), Error> where W: Write + Seek { // TIFF signature and the offset of the 0th IFD. @@ -428,7 +424,7 @@ fn write_ifd_and_fields( for f in fields { let (typ, cnt, mut valbuf) = try!(compose_value::(&f.value)); if cnt as u32 as usize != cnt { - return Err(Error::InvalidFormat("Too long array")); + return Err(Error::TooBig("Too long array")); } try!(E::writeu16(&mut ifd, f.tag.number())); try!(E::writeu16(&mut ifd, typ)); @@ -552,7 +548,7 @@ fn compose_value(value: &Value) Ok((12, vec.len(), buf)) }, Value::Unknown(_, _, _) => - Err(Error::InvalidFormat("Cannot write unknown field types")), + Err(Error::NotSupported("Cannot write unknown field types")), } } @@ -570,7 +566,7 @@ fn pad_and_get_offset(w: &mut W) -> Result where W: Write + Seek { let mut pos = try!(w.seek(SeekFrom::Current(0))); if pos >= (1 << 32) - 1 { - return Err(Error::InvalidFormat("Offset too large")); + return Err(Error::TooBig("Offset too large")); } if pos % 2 != 0 { try!(w.write_all(&[0])); @@ -583,7 +579,7 @@ fn get_offset(w: &mut W) -> Result where W: Write + Seek { let pos = try!(w.seek(SeekFrom::Current(0))); if pos as u32 as u64 != pos { - return Err(Error::InvalidFormat("Offset too large")); + return Err(Error::TooBig("Offset too large")); } Ok(pos as u32) } diff --git a/tests/rwrcmp.rs b/tests/rwrcmp.rs index 89a5898..101b7ac 100644 --- a/tests/rwrcmp.rs +++ b/tests/rwrcmp.rs @@ -99,7 +99,7 @@ fn rwr_compare

(path: P) where P: AsRef { #[cfg(not(test))] match writer.write(&mut out, reader1.little_endian()) { Ok(_) => {}, - Err(Error::InvalidFormat("Cannot write unknown field types")) => { + Err(Error::NotSupported(_)) => { println!("{}: Contains unknown type", path.display()); return; },