openslide_rs/
errors.rs

1//! This module contains errors defined in this library
2//!
3
4use std::{ffi::NulError, num::TryFromIntError};
5
6use thiserror::Error;
7
8/// Enum defining all possible error when manipulating `OpenSlide` struct
9#[derive(Error, Debug, Clone)]
10pub enum OpenSlideError {
11    /// FFI string conversion error
12    /// Integer conversion error
13    #[error("Internal error: {0}")]
14    InternalError(String),
15
16    /// Image feature related error
17    /// Example: Error while resizing, bad dimension ..
18    #[error("Internal error: {0}")]
19    ImageError(String),
20
21    #[error("File {0} does not exist")]
22    MissingFile(String),
23
24    #[error("Unsupported file format: {0}")]
25    UnsupportedFile(String),
26
27    /// OpenSlide lib error
28    #[error("OpenSlide error: {0}")]
29    CoreError(String),
30}
31
32impl From<TryFromIntError> for OpenSlideError {
33    fn from(err: TryFromIntError) -> Self {
34        OpenSlideError::InternalError(err.to_string())
35    }
36}
37
38impl From<NulError> for OpenSlideError {
39    fn from(err: NulError) -> Self {
40        OpenSlideError::InternalError(err.to_string())
41    }
42}