libobs_bootstrapper/
error.rs

1#[derive(Debug)]
2pub enum ObsBootstrapError {
3    GeneralError(String),
4    InvalidFormatError(String),
5    /// Contains context and specific reqwest error
6    DownloadError(&'static str, reqwest::Error),
7    ExtractError(String),
8    /// Contains context and specific io error
9    IoError(&'static str, std::io::Error),
10    LibLoadingError(&'static str, libloading::Error),
11    VersionError(String),
12    /// This error indicates that the downloaded file's hash did not match the expected hash
13    HashMismatchError,
14    /// This error should never happen, report to maintainers
15    InvalidState,
16    /// This error is emitted when a status handler returns an error instead of an Ok(()). This is the Error type that your handler uses.
17    Abort(Box<dyn std::error::Error + Send + Sync>),
18}
19
20impl std::fmt::Display for ObsBootstrapError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            ObsBootstrapError::GeneralError(e) => write!(f, "Bootstrapper error: {:?}", e),
24            ObsBootstrapError::DownloadError(context, e) => {
25                write!(f, "Bootstrapper download error: {:?} ({:?})", context, e)
26            }
27            ObsBootstrapError::ExtractError(e) => write!(f, "Bootstrapper extract error: {:?}", e),
28            ObsBootstrapError::IoError(context, error) => write!(f, "{}: {:?}", context, error),
29            ObsBootstrapError::VersionError(e) => write!(f, "Version error: {:?}", e),
30            ObsBootstrapError::InvalidFormatError(e) => write!(f, "Invalid format error: {:?}", e),
31            ObsBootstrapError::HashMismatchError => write!(
32                f,
33                "Hash mismatch error: The downloaded file's hash did not match the expected hash"
34            ),
35            ObsBootstrapError::InvalidState => write!(
36                f,
37                "Invalid state error: This error should never happen, please report to maintainers"
38            ),
39            ObsBootstrapError::Abort(e) => {
40                write!(f, "Operation aborted by status handler: {:?}", e)
41            }
42            ObsBootstrapError::LibLoadingError(context, e) => {
43                write!(f, "Library loading error: {}: {:?}", context, e)
44            }
45        }
46    }
47}
48impl std::error::Error for ObsBootstrapError {}