Skip to main content

libobsbot_core/
error.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! Error type for libobsbot-core.
3
4use thiserror::Error;
5
6/// Result type used throughout libobsbot-core.
7pub type Result<T, E = Error> = core::result::Result<T, E>;
8
9/// Errors produced by libobsbot.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// USB transport failure.
14    #[error("usb: {0}")]
15    Usb(String),
16
17    /// Operation timed out before the camera responded.
18    #[error("timeout")]
19    Timeout,
20
21    /// Camera returned a response that did not match the expected shape.
22    #[error("bad response for selector {selector:#04x}: {bytes:02x?}")]
23    BadResponse {
24        /// XU selector the response was for.
25        selector: u8,
26        /// Raw response bytes for debugging.
27        bytes: Vec<u8>,
28    },
29
30    /// Method is not supported on this platform or for this device.
31    #[error("unsupported: {0}")]
32    Unsupported(&'static str),
33
34    /// No matching device was found.
35    #[error("not found")]
36    NotFound,
37
38    /// Argument value lies outside the camera's accepted range.
39    #[error("out of range")]
40    OutOfRange,
41
42    /// Camera firmware is older than the minimum supported revision.
43    #[error("firmware {observed} is older than required {required}")]
44    FirmwareUnsupported {
45        /// Firmware version reported by the camera.
46        observed: String,
47        /// Minimum firmware version this build supports.
48        required: String,
49    },
50}