Skip to main content

libobs_bootstrapper/
error.rs

1#[derive(Debug)]
2pub enum ObsBootstrapError {
3    /// Legacy variant retained for source compatibility. New bootstrap calls do
4    /// not return it.
5    RuntimeBootstrapDisabled,
6    /// OBS is already mapped into this process, so replacing its runtime files
7    /// would be unsafe. On Windows, enable delay loading and bootstrap first.
8    RuntimeAlreadyLoaded,
9    GeneralError(String),
10    UnsupportedPlatform(String),
11    InvalidFormatError(String),
12    ExtractError(String),
13    /// Contains context and specific I/O error.
14    IoError(&'static str, std::io::Error),
15    LibLoadingError(&'static str, libloading::Error),
16    VersionError(String),
17    HashMismatchError,
18    InvalidState,
19    Abort(Box<dyn std::error::Error + Send + Sync>),
20}
21
22impl std::fmt::Display for ObsBootstrapError {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            Self::RuntimeBootstrapDisabled => write!(f, "Runtime OBS bootstrap is disabled"),
26            Self::RuntimeAlreadyLoaded => write!(
27                f,
28                "OBS is already loaded in this process; bootstrap/update must run before the first OBS call"
29            ),
30            Self::GeneralError(e) => write!(f, "Bootstrapper error: {e}"),
31            Self::UnsupportedPlatform(e) => write!(f, "Unsupported platform: {e}"),
32            Self::ExtractError(e) => write!(f, "Bootstrapper extract error: {e}"),
33            Self::IoError(context, error) => write!(f, "{context}: {error}"),
34            Self::VersionError(e) => write!(f, "Version error: {e}"),
35            Self::InvalidFormatError(e) => write!(f, "Invalid format error: {e}"),
36            Self::HashMismatchError => write!(
37                f,
38                "Hash mismatch error: the downloaded file did not match its expected SHA-256"
39            ),
40            Self::InvalidState => write!(f, "Invalid bootstrapper state"),
41            Self::Abort(e) => write!(f, "Operation aborted by status handler: {e}"),
42            Self::LibLoadingError(context, e) => {
43                write!(f, "Library loading error: {context}: {e}")
44            }
45        }
46    }
47}
48
49impl std::error::Error for ObsBootstrapError {}