diff --git a/Cargo.lock b/Cargo.lock index 4abce99677..9023597416 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,6 +54,7 @@ dependencies = [ "libc", "minijail", "power_monitor", + "remain", "resources", "sync", "thiserror", diff --git a/arch/Cargo.toml b/arch/Cargo.toml index 1340f6e3ab..647b56f527 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -10,16 +10,17 @@ gdb = ["gdbstub_arch"] [dependencies] acpi_tables = { path = "../acpi_tables" } +base = { path = "../base" } devices = { path = "../devices" } gdbstub_arch = { version = "0.1.0", optional = true } hypervisor = { path = "../hypervisor" } kernel_cmdline = { path = "../kernel_cmdline" } libc = "*" minijail = "*" +power_monitor = { path = "../power_monitor" } +remain = "*" resources = { path = "../resources" } sync = { path = "../sync" } -base = { path = "../base" } +thiserror = "1.0.20" vm_control = { path = "../vm_control" } vm_memory = { path = "../vm_memory" } -power_monitor = { path = "../power_monitor" } -thiserror = "1.0.20" diff --git a/arch/src/fdt.rs b/arch/src/fdt.rs index 944e5025ad..8e035025a6 100644 --- a/arch/src/fdt.rs +++ b/arch/src/fdt.rs @@ -11,28 +11,30 @@ use std::ffi::CString; use std::io; use std::mem::size_of; +use remain::sorted; use thiserror::Error as ThisError; +#[sorted] #[derive(ThisError, Debug)] pub enum Error { + #[error("Parse error reading FDT parameters")] + FdtFileParseError, + #[error("Error writing FDT to guest memory")] + FdtGuestMemoryWriteError, + #[error("I/O error reading FDT parameters code={0}")] + FdtIoError(io::Error), + #[error("Strings cannot contain NUL")] + InvalidString, + #[error("Attempted to end a node that was not the most recent")] + OutOfOrderEndNode, #[error("Properties may not be added after a node has been ended")] PropertyAfterEndNode, #[error("Property value size must fit in 32 bits")] PropertyValueTooLarge, #[error("Total size must fit in 32 bits")] TotalSizeTooLarge, - #[error("Strings cannot contain NUL")] - InvalidString, - #[error("Attempted to end a node that was not the most recent")] - OutOfOrderEndNode, #[error("Attempted to call finish without ending all nodes")] UnclosedNode, - #[error("Error writing FDT to guest memory")] - FdtGuestMemoryWriteError, - #[error("Parse error reading FDT parameters")] - FdtFileParseError, - #[error("I/O error reading FDT parameters code={0}")] - FdtIoError(io::Error), } pub type Result = std::result::Result; diff --git a/arch/src/serial.rs b/arch/src/serial.rs index 24443f56f9..c88509b96d 100644 --- a/arch/src/serial.rs +++ b/arch/src/serial.rs @@ -17,39 +17,33 @@ use std::time::Duration; use base::{error, info, read_raw_stdin, syslog, AsRawDescriptor, Event, RawDescriptor}; use devices::{Bus, ProtectionType, ProxyDevice, Serial, SerialDevice}; use minijail::Minijail; +use remain::sorted; use sync::Mutex; +use thiserror::Error as ThisError; use crate::DeviceRegistrationError; -#[derive(Debug)] +#[sorted] +#[derive(ThisError, Debug)] pub enum Error { + #[error("Unable to clone an Event: {0}")] CloneEvent(base::Error), + #[error("Unable to open/create file: {0}")] FileError(std::io::Error), - InvalidSerialHardware(String), - InvalidSerialType(String), + #[error("Serial device path is invalid")] InvalidPath, + #[error("Invalid serial hardware: {0}")] + InvalidSerialHardware(String), + #[error("Invalid serial type: {0}")] + InvalidSerialType(String), + #[error("Serial device type file requires a path")] PathRequired, + #[error("Failed to create unbound socket")] SocketCreateFailed, + #[error("Serial device type {0} not implemented")] Unimplemented(SerialType), } -impl Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use self::Error::*; - - match self { - CloneEvent(e) => write!(f, "unable to clone an Event: {}", e), - FileError(e) => write!(f, "unable to open/create file: {}", e), - InvalidSerialHardware(e) => write!(f, "invalid serial hardware: {}", e), - InvalidSerialType(e) => write!(f, "invalid serial type: {}", e), - InvalidPath => write!(f, "serial device path is invalid"), - PathRequired => write!(f, "serial device type file requires a path"), - SocketCreateFailed => write!(f, "failed to create unbound socket"), - Unimplemented(e) => write!(f, "serial device type {} not implemented", e.to_string()), - } - } -} - /// Enum for possible type of serial devices #[derive(Clone, Debug)] pub enum SerialType { @@ -462,25 +456,15 @@ pub fn add_serial_devices( Ok(()) } -#[derive(Debug)] +#[sorted] +#[derive(ThisError, Debug)] pub enum GetSerialCmdlineError { + #[error("Error appending to cmdline: {0}")] KernelCmdline(kernel_cmdline::Error), + #[error("Hardware {0} not supported as earlycon")] UnsupportedEarlyconHardware(SerialHardware), } -impl Display for GetSerialCmdlineError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use self::GetSerialCmdlineError::*; - - match self { - KernelCmdline(e) => write!(f, "error appending to cmdline: {}", e), - UnsupportedEarlyconHardware(hw) => { - write!(f, "hardware {} not supported as earlycon", hw) - } - } - } -} - pub type GetSerialCmdlineResult = std::result::Result; /// Add serial options to the provided `cmdline` based on `serial_parameters`.