Don't expose third-party errors in public API.
This commit is contained in:
committed by
Dustin J. Mitchell
parent
f56296ea93
commit
2f7196dbfc
@@ -19,20 +19,25 @@ pub enum Error {
|
|||||||
/// A usage error
|
/// A usage error
|
||||||
#[error("User Error: {0}")]
|
#[error("User Error: {0}")]
|
||||||
Usage(String),
|
Usage(String),
|
||||||
|
/// A general error.
|
||||||
/// Error conversions.
|
|
||||||
#[error(transparent)]
|
|
||||||
Http(#[from] ureq::Error),
|
|
||||||
#[error(transparent)]
|
|
||||||
Io(#[from] io::Error),
|
|
||||||
#[error(transparent)]
|
|
||||||
Json(#[from] serde_json::Error),
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Other(#[from] anyhow::Error),
|
Other(#[from] anyhow::Error),
|
||||||
#[error("Third Party Sqlite Error")]
|
|
||||||
Rusqlite(#[from] rusqlite::Error),
|
|
||||||
#[error(transparent)]
|
|
||||||
Sqlite(#[from] crate::storage::sqlite::SqliteError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert private and third party errors into Error::Other.
|
||||||
|
macro_rules! convert_error {
|
||||||
|
( $error:ty ) => {
|
||||||
|
impl From<$error> for Error {
|
||||||
|
fn from(err: $error) -> Self {
|
||||||
|
Self::Other(err.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
convert_error!(ureq::Error);
|
||||||
|
convert_error!(io::Error);
|
||||||
|
convert_error!(serde_json::Error);
|
||||||
|
convert_error!(rusqlite::Error);
|
||||||
|
convert_error!(crate::storage::sqlite::SqliteError);
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|||||||
Reference in New Issue
Block a user