Skip to main content

managed_lhapdf/
error.rs

1use cxx::Exception;
2use thiserror::Error;
3
4/// Error struct that wraps all exceptions thrown by the LHAPDF library.
5#[derive(Debug, Error)]
6pub enum Error {
7    /// Captures an exception coming from the C++ LHAPDF library.
8    #[error(transparent)]
9    LhapdfException(Exception),
10    /// General error with a message.
11    #[error("{0}")]
12    General(String),
13    /// A 404 'file not found' error when trying to download a file over HTTP.
14    #[error("file not found")]
15    Http404,
16    /// Errors from within this library.
17    #[error(transparent)]
18    Other(anyhow::Error),
19}
20
21/// Type definition for results with an [`enum@Error`].
22pub type Result<T> = std::result::Result<T, Error>;
23
24impl From<Exception> for Error {
25    fn from(err: Exception) -> Self {
26        Self::LhapdfException(err)
27    }
28}
29
30impl From<std::io::Error> for Error {
31    fn from(err: std::io::Error) -> Self {
32        Self::Other(anyhow::Error::new(err))
33    }
34}