mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 20:19:07 +00:00
gpu_display: convert to ThisError and sort
BUG=b:197143586 TEST=cargo check Change-Id: I461144d021314984e9ec2c738144b8e3065efcf4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105079 Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
620b0f033e
commit
c3f546906b
3 changed files with 24 additions and 27 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -535,6 +535,8 @@ dependencies = [
|
|||
"libc",
|
||||
"linux_input_sys",
|
||||
"pkg-config",
|
||||
"remain",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -12,6 +12,8 @@ data_model = { path = "../data_model" }
|
|||
libc = "*"
|
||||
base = { path = "../base" }
|
||||
linux_input_sys = { path = "../linux_input_sys" }
|
||||
remain = "*"
|
||||
thiserror = "*"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "=1.0.25"
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
//! Wayland or X.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::{self, Display};
|
||||
use std::io::Error as IoError;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
use base::{AsRawDescriptor, Error as BaseError, EventType, PollToken, RawDescriptor, WaitContext};
|
||||
use data_model::VolatileSlice;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
mod event_device;
|
||||
mod gpu_display_stub;
|
||||
|
@ -26,57 +27,49 @@ pub use event_device::{EventDevice, EventDeviceKind};
|
|||
use linux_input_sys::virtio_input_event;
|
||||
|
||||
/// An error generated by `GpuDisplay`.
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum GpuDisplayError {
|
||||
/// An internal allocation failed.
|
||||
#[error("internal allocation failed")]
|
||||
Allocate,
|
||||
/// A base error occurred.
|
||||
#[error("received a base error: {0}")]
|
||||
BaseError(BaseError),
|
||||
/// Connecting to the compositor failed.
|
||||
#[error("failed to connect to compositor")]
|
||||
Connect,
|
||||
/// Creating event file descriptor failed.
|
||||
#[error("failed to create event file descriptor")]
|
||||
CreateEvent,
|
||||
/// A base error occurred.
|
||||
BaseError(BaseError),
|
||||
/// Failed to create a surface on the compositor.
|
||||
#[error("failed to crate surface on the compositor")]
|
||||
CreateSurface,
|
||||
/// Failed to import a buffer to the compositor.
|
||||
#[error("failed to import a buffer to the compositor")]
|
||||
FailedImport,
|
||||
/// The path is invalid.
|
||||
InvalidPath,
|
||||
/// The import ID is invalid.
|
||||
#[error("invalid import ID")]
|
||||
InvalidImportId,
|
||||
/// The path is invalid.
|
||||
#[error("invalid path")]
|
||||
InvalidPath,
|
||||
/// The surface ID is invalid.
|
||||
#[error("invalid surface ID")]
|
||||
InvalidSurfaceId,
|
||||
/// An input/output error occured.
|
||||
#[error("an input/output error occur: {0}")]
|
||||
IoError(IoError),
|
||||
/// A required feature was missing.
|
||||
#[error("required feature was missing: {0}")]
|
||||
RequiredFeature(&'static str),
|
||||
/// The method is unsupported by the implementation.
|
||||
#[error("unsupported by the implementation")]
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
pub type GpuDisplayResult<T> = std::result::Result<T, GpuDisplayError>;
|
||||
|
||||
impl Display for GpuDisplayError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::GpuDisplayError::*;
|
||||
|
||||
match self {
|
||||
Allocate => write!(f, "internal allocation failed"),
|
||||
Connect => write!(f, "failed to connect to compositor"),
|
||||
CreateEvent => write!(f, "failed to create event file descriptor"),
|
||||
BaseError(e) => write!(f, "received a base error: {}", e),
|
||||
CreateSurface => write!(f, "failed to crate surface on the compositor"),
|
||||
FailedImport => write!(f, "failed to import a buffer to the compositor"),
|
||||
InvalidPath => write!(f, "invalid path"),
|
||||
InvalidImportId => write!(f, "invalid import ID"),
|
||||
InvalidSurfaceId => write!(f, "invalid surface ID"),
|
||||
IoError(e) => write!(f, "an input/output error occur: {}", e),
|
||||
RequiredFeature(feature) => write!(f, "required feature was missing: {}", feature),
|
||||
Unsupported => write!(f, "unsupported by the implementation"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BaseError> for GpuDisplayError {
|
||||
fn from(e: BaseError) -> GpuDisplayError {
|
||||
GpuDisplayError::BaseError(e)
|
||||
|
|
Loading…
Reference in a new issue