image_hdr/
error.rs

1//! Error definitions for the library
2
3use image::ImageError;
4#[cfg(feature = "read-raw-image")]
5use rawloader::RawLoaderError;
6use std::fmt::{Debug, Display, Formatter};
7use std::io;
8use thiserror::Error;
9
10/// Represents error occurred during the raw image decoding pipeline.
11#[derive(Error, Debug)]
12pub struct RawPipelineError(pub String);
13
14impl Display for RawPipelineError {
15    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16        std::fmt::Display::fmt(&self.0, f)
17    }
18}
19
20impl From<String> for RawPipelineError {
21    fn from(value: String) -> Self {
22        Self(value)
23    }
24}
25
26/// Represents errors that cannot be categorised as any other error types.
27#[derive(Error, Debug)]
28pub struct UnknownError(pub String);
29
30impl Display for UnknownError {
31    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32        std::fmt::Display::fmt(&self.0, f)
33    }
34}
35
36impl From<String> for UnknownError {
37    fn from(value: String) -> Self {
38        Self(value)
39    }
40}
41
42/// Error that can be returned by any of the methods in the library.
43#[derive(Debug, Error)]
44pub enum Error {
45    /// Represents image or raw image decoding error
46    #[error("Unable to decode raw image")]
47    #[cfg_attr(not(feature = "read-raw-image"), non_exhaustive)]
48    DecodeError(
49        #[from]
50        #[cfg(feature = "read-raw-image")]
51        RawLoaderError,
52    ),
53    /// Represents raw image pipeline error
54    #[error("Unable to decode raw image")]
55    RawPipeline(#[from] RawPipelineError),
56    /// Represents error occurred while reading exif data or if necessary exif data is missing.
57    #[error("Unable to read exif data")]
58    ExifError(#[from] exif::Error),
59    /// Represents error occurred while reading/writing image files
60    #[error("Unable to read file")]
61    IoError(#[from] io::Error),
62    /// Represents error occurred while converting between different image formats or while writing
63    /// buffers from raw/processed pixel data.
64    #[error("Unable to process image")]
65    ImageError(#[from] ImageError),
66    /// Represents error caused by invalid input to the crate's functions
67    #[error("Invalid value for {parameter_name:?}: {message:?}")]
68    InputError {
69        /// Name of the parameter for which error occurred
70        parameter_name: String,
71        /// A message explaining why parameter is invalid
72        message: String,
73    },
74    /// Represents errors that cannot be categorised as any other error types.
75    #[error("{0}")]
76    UnknownError(#[from] UnknownError),
77}