Skip to main content

pixelflux/
error.rs

1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7//! The one error type the public API returns. Each variant names the part of pixelflux
8//! that refused: the settings a consumer handed over, a capture, the compositor, or a
9//! capability the session lacks (a compositor without the virtual-keyboard protocol). The
10//! Python bridge maps them to its exceptions (`ValueError` for settings,
11//! `VirtualKeyboardUnavailable` for a missing capability, `RuntimeError` otherwise).
12
13use std::fmt;
14
15/// Why a call into pixelflux failed.
16#[derive(Clone, Debug, PartialEq, Eq)]
17pub enum Error {
18    /// A setting is outside what the backend takes.
19    Settings(String),
20    /// A capture could not start, stop, or be reconfigured.
21    Capture(String),
22    /// The compositor refused or did not answer a command.
23    Compositor(String),
24    /// The session lacks the capability the call needs.
25    Unavailable(String),
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Error::Settings(m)
32            | Error::Capture(m)
33            | Error::Compositor(m)
34            | Error::Unavailable(m) => f.write_str(m),
35        }
36    }
37}
38
39impl std::error::Error for Error {}
40
41impl From<String> for Error {
42    fn from(m: String) -> Self {
43        Error::Capture(m)
44    }
45}