Skip to main content

cpdb_sys/
error.rs

1//! `cpdb-sys` workspace error type and `Result` alias.
2
3use std::ffi::NulError;
4use std::str::Utf8Error;
5use thiserror::Error;
6
7/// Errors that originate from the cpdb-rs bindings.
8///
9/// This type is `#[non_exhaustive]` — match arms must include a wildcard
10/// so adding variants in future minor releases is not a breaking change.
11#[non_exhaustive]
12#[derive(Error, Debug)]
13pub enum CpdbError {
14    /// A C function returned `NULL` where a valid pointer was required.
15    #[error("Null pointer encountered")]
16    NullPointer,
17
18    /// A printer object pointer is invalid or has been released.
19    #[error("Invalid printer object")]
20    InvalidPrinter,
21
22    /// A lookup (printer, option, media, translation, ...) returned no result.
23    #[error("Not found: {0}")]
24    NotFound(String),
25
26    /// A printer-side operation failed (set default, accept jobs, ...).
27    #[error("Printer error: {0}")]
28    PrinterError(String),
29
30    /// A print job submission failed.
31    #[error("Print job failed: {0}")]
32    JobFailed(String),
33
34    /// A backend-side operation failed.
35    #[error("Backend error: {0}")]
36    BackendError(String),
37
38    /// A frontend-side operation failed (D-Bus, lifecycle, ...).
39    #[error("Frontend error: {0}")]
40    FrontendError(String),
41
42    /// A printer option could not be parsed or applied.
43    #[error("Option error: {0}")]
44    OptionError(String),
45
46    /// A C string returned by cpdb-libs contained invalid UTF-8.
47    #[error("Invalid UTF-8 string: {0}")]
48    Utf8Error(#[from] Utf8Error),
49
50    /// A Rust string contained an interior NUL byte.
51    #[error("Nul byte in string: {0}")]
52    NulError(#[from] NulError),
53
54    /// An I/O error bubbled up from std::io.
55    #[error("IO error: {0}")]
56    IoError(#[from] std::io::Error),
57    /// An unexpected status code was returned.
58    #[error("Invalid status code: {0}")]
59    InvalidStatus(i32),
60    /// The requested operation is not supported.
61    #[error("Unsupported operation")]
62    Unsupported,
63}
64
65/// Shorthand `Result` alias used throughout the crate.
66pub type Result<T> = std::result::Result<T, CpdbError>;