display_utils/
error.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl_fuchsia_hardware_display_types::ConfigResult;
6
7use futures::channel::mpsc;
8use thiserror::Error;
9
10use crate::controller::VsyncEvent;
11
12/// Library error type.
13#[derive(Error, Debug)]
14pub enum Error {
15    /// Error encountered while connecting to a display-coordinator device via devfs.
16    #[error("could not find a display-coordinator device")]
17    DeviceNotFound,
18
19    /// No displays were reported by the display driver when expected.
20    #[error("device did not enumerate initial displays")]
21    NoDisplays,
22
23    /// A request handling task (such as one that owns a FIDL event stream that can only be
24    /// started once) was already been initiated before.
25    #[error("a singleton task was already initiated")]
26    AlreadyRequested,
27
28    /// Error while allocating shared sysmem buffers.
29    #[error("sysmem buffer collection allocation failed, or invalid response from sysmem")]
30    BuffersNotAllocated,
31
32    /// Error while establishing a connection to sysmem.
33    #[error("error while setting up a sysmem connection")]
34    SysmemConnection,
35
36    /// Ran out of free client-assigned identifiers.
37    #[error("ran out of identifiers")]
38    IdsExhausted,
39
40    /// Path to the device is invalid (e.g. containing invalid
41    /// characters).
42    #[error("invalid device path")]
43    DevicePathInvalid,
44
45    /// Wrapper for errors from FIDL bindings.
46    #[error("FIDL error: {0}")]
47    FidlError(#[from] fidl::Error),
48
49    /// Wrapper for system file I/O errors.
50    #[error("OS I/O error: {0}")]
51    IoError(#[from] std::io::Error),
52
53    /// Wrapper for errors from zircon syscalls.
54    #[error("zircon error: {0}")]
55    ZxError(#[from] zx::Status),
56
57    /// Wrapper for errors from FIDL device connections.
58    #[error("Device connection error: {0}")]
59    DeviceConnectionError(anyhow::Error),
60
61    /// Wrapper for errors from fuchsia-fs.
62    #[error("filesystem error: {0}")]
63    FsError(#[from] fuchsia_fs::node::OpenError),
64
65    /// Wrapper for errors from fuchsia-fs watcher creation.
66    #[error("failed to create directory watcher: {0}")]
67    WatcherCreateError(#[from] fuchsia_fs::directory::WatcherCreateError),
68
69    /// Wrapper for errors from the fuchsia-fs watcher stream.
70    #[error("directory watcher stream produced error: {0}")]
71    WatcherStreamError(#[from] fuchsia_fs::directory::WatcherStreamError),
72
73    /// Error that occurred while notifying vsync event listeners over an in-process async channel.
74    #[error("failed to notify vsync: {0}")]
75    CouldNotSendVsyncEvent(#[from] mpsc::TrySendError<VsyncEvent>),
76
77    /// UTF-8 validation error.
78    #[error("invalid UTF-8 string")]
79    InvalidUtf8(#[from] std::str::Utf8Error),
80}
81
82/// Library Result type alias.
83pub type Result<T> = std::result::Result<T, Error>;
84
85/// An error generated by `fuchsia.hardware.display.Controller.CheckConfig`.
86#[derive(Debug, Error)]
87pub enum ConfigError {
88    /// Failure due to an invalid configuration.
89    #[error("invalid configuration - error_code: {error_code:#?}")]
90    Invalid {
91        /// The reason for the failure.
92        error_code: ConfigResult,
93    },
94
95    /// Failure due to a FIDL transport error.
96    #[error("FIDL channel error")]
97    Fidl(#[from] fidl::Error),
98}
99
100impl ConfigError {
101    /// Create an `Invalid` configuration error variant from FIDL output.
102    pub fn invalid(error_code: ConfigResult) -> ConfigError {
103        ConfigError::Invalid { error_code }
104    }
105}