Improved error messages for inflate decompression

This commit is contained in:
Masterchef365 committed 2019-10-02 21:06:11 -07:00
1 parent 205626bd62
commit 6f9f2adfbf
3 files changed
+27 -9

No files matched your search

+21 -1
View File
@@ -5,6 +5,7 @@ use std::string;
use decoder::ifd::{Tag, Value};
use decoder::{CompressionMethod, PhotometricInterpretation, PlanarConfiguration};
use miniz_oxide::inflate::TINFLStatus;
use ColorType;
/// Tiff error kinds.
@@ -34,6 +35,7 @@ pub enum TiffFormatError {
UnknownPredictor(u32),
UnsignedIntegerExpected(Value),
SignedIntegerExpected(Value),
InflateError(InflateError),
}
impl fmt::Display for TiffFormatError {
@@ -55,10 +57,28 @@ impl fmt::Display for TiffFormatError {
SignedIntegerExpected(ref val) => {
write!(fmt, "Expected signed integer, {:?} found.", val)
}
InflateError(_) => write!(fmt, "Failed to decode inflate data."),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct InflateError {
status: TINFLStatus,
}
impl From<TINFLStatus> for TiffFormatError {
fn from(status: TINFLStatus) -> Self {
TiffFormatError::InflateError(InflateError { status })
}
}
impl From<TINFLStatus> for TiffError {
fn from(status: TINFLStatus) -> Self {
TiffError::FormatError(status.into())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TiffUnsupportedError {
HorizontalPredictor(ColorType),
@@ -138,7 +158,7 @@ impl Error for TiffError {
}
}
fn cause(&self) -> Option<& dyn Error> {
fn cause(&self) -> Option<&dyn Error> {
match *self {
TiffError::IoError(ref e) => Some(e),
_ => None,