Skip to main content

denise_fbdev/
error.rs

1//! Failures from the fbdev backend.
2
3use std::io;
4use std::path::PathBuf;
5
6use denise::SurfaceError;
7
8use crate::info::FbInfoError;
9
10/// Something went wrong driving `/dev/fbN`.
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum FbdevError {
14    /// No `/dev/fb*` node exists.
15    ///
16    /// Expected on a modern kernel: fbdev is optional, and where it does exist it
17    /// is usually DRM's emulation layer rather than a driver of its own.
18    #[error("no framebuffer device found")]
19    NoDevice,
20
21    /// The device node could not be opened.
22    ///
23    /// Writing to a framebuffer needs the `video` group, or root.
24    #[error("opening {path}")]
25    Open {
26        /// The device that failed.
27        path: PathBuf,
28        /// The underlying failure.
29        #[source]
30        source: io::Error,
31    },
32
33    /// A sysfs attribute could not be read.
34    #[error("reading {path}")]
35    Sysfs {
36        /// The attribute that failed.
37        path: PathBuf,
38        /// The underlying failure.
39        #[source]
40        source: io::Error,
41    },
42
43    /// The geometry could not be understood.
44    #[error(transparent)]
45    Geometry(#[from] FbInfoError),
46
47    /// The framebuffer could not be mapped into this process.
48    #[error("mapping the framebuffer")]
49    Map(#[source] io::Error),
50
51    /// The mapping is smaller than the reported geometry needs.
52    #[error("framebuffer is {actual} bytes but the geometry needs {required}")]
53    TooSmall {
54        /// Bytes the geometry requires.
55        required: usize,
56        /// Bytes actually mapped.
57        actual: usize,
58    },
59}
60
61impl From<FbdevError> for SurfaceError {
62    fn from(err: FbdevError) -> Self {
63        SurfaceError::backend(err)
64    }
65}