vmm: Use thiserror/anyhow for vmm::Error

This gives a nicer user experience and this error can now be used as the
source for other errors based off this.

See: #1910

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-10-26 16:11:02 +00:00
parent 6d4656c68f
commit dfd21cbfc5
3 changed files with 35 additions and 16 deletions

1
Cargo.lock generated
View File

@ -1649,6 +1649,7 @@ dependencies = [
"serde_json", "serde_json",
"signal-hook", "signal-hook",
"tempfile", "tempfile",
"thiserror",
"url", "url",
"vfio-ioctls", "vfio-ioctls",
"virtio-devices", "virtio-devices",

View File

@ -13,13 +13,13 @@ kvm = ["hypervisor/kvm"]
io_uring = ["virtio-devices/io_uring"] io_uring = ["virtio-devices/io_uring"]
[dependencies] [dependencies]
arc-swap = ">=0.4.4"
bitflags = ">=1.2.1"
clap = "2.33.3"
acpi_tables = { path = "../acpi_tables", optional = true } acpi_tables = { path = "../acpi_tables", optional = true }
anyhow = "1.0" anyhow = "1.0"
arc-swap = ">=0.4.4"
arch = { path = "../arch" } arch = { path = "../arch" }
bitflags = ">=1.2.1"
block_util = { path = "../block_util" } block_util = { path = "../block_util" }
clap = "2.33.3"
devices = { path = "../devices" } devices = { path = "../devices" }
epoll = ">=4.0.1" epoll = ">=4.0.1"
hypervisor = { path = "../hypervisor" } hypervisor = { path = "../hypervisor" }
@ -35,6 +35,9 @@ seccomp = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v
serde = {version = ">=1.0.27", features = ["rc"] } serde = {version = ">=1.0.27", features = ["rc"] }
serde_derive = ">=1.0.27" serde_derive = ">=1.0.27"
serde_json = ">=1.0.9" serde_json = ">=1.0.9"
signal-hook = "0.1.16"
tempfile = "3.1.0"
thiserror = "1.0"
url = "2.1.1" url = "2.1.1"
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" } vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
virtio-devices = { path = "../virtio-devices" } virtio-devices = { path = "../virtio-devices" }
@ -44,8 +47,6 @@ vm-memory = { version = "0.3.0", features = ["backend-mmap", "backend-atomic"] }
vm-migration = { path = "../vm-migration" } vm-migration = { path = "../vm-migration" }
vm-virtio = { path = "../vm-virtio" } vm-virtio = { path = "../vm-virtio" }
vmm-sys-util = { version = ">=0.5.0", features = ["with-serde"] } vmm-sys-util = { version = ">=0.5.0", features = ["with-serde"] }
signal-hook = "0.1.16"
tempfile = "3.1.0"
[dependencies.linux-loader] [dependencies.linux-loader]

View File

@ -39,6 +39,7 @@ use std::path::PathBuf;
use std::sync::mpsc::{Receiver, RecvError, SendError, Sender}; use std::sync::mpsc::{Receiver, RecvError, SendError, Sender};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::{result, thread}; use std::{result, thread};
use thiserror::Error;
use vm_migration::{Pausable, Snapshottable, Transportable}; use vm_migration::{Pausable, Snapshottable, Transportable};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -57,55 +58,71 @@ pub mod vm;
mod acpi; mod acpi;
/// Errors associated with VMM management /// Errors associated with VMM management
#[derive(Debug)] #[derive(Debug, Error)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
pub enum Error { pub enum Error {
/// API request receive error /// API request receive error
ApiRequestRecv(RecvError), #[error("Error receiving API request: {0}")]
ApiRequestRecv(#[source] RecvError),
/// API response send error /// API response send error
ApiResponseSend(SendError<ApiResponse>), #[error("Error sending API request: {0}")]
ApiResponseSend(#[source] SendError<ApiResponse>),
/// Cannot bind to the UNIX domain socket path /// Cannot bind to the UNIX domain socket path
Bind(io::Error), #[error("Error binding to UNIX domain socket: {0}")]
Bind(#[source] io::Error),
/// Cannot clone EventFd. /// Cannot clone EventFd.
EventFdClone(io::Error), #[error("Error cloning EventFd: {0}")]
EventFdClone(#[source] io::Error),
/// Cannot create EventFd. /// Cannot create EventFd.
EventFdCreate(io::Error), #[error("Error creating EventFd: {0}")]
EventFdCreate(#[source] io::Error),
/// Cannot read from EventFd. /// Cannot read from EventFd.
EventFdRead(io::Error), #[error("Error reading from EventFd: {0}")]
EventFdRead(#[source] io::Error),
/// Cannot create epoll context. /// Cannot create epoll context.
Epoll(io::Error), #[error("Error creating epoll context: {0}")]
Epoll(#[source] io::Error),
/// Cannot create HTTP thread /// Cannot create HTTP thread
HttpThreadSpawn(io::Error), #[error("Error spawning HTTP thread: {0}")]
HttpThreadSpawn(#[source] io::Error),
/// Cannot handle the VM STDIN stream /// Cannot handle the VM STDIN stream
#[error("Error handling VM stdin: {0:?}")]
Stdin(VmError), Stdin(VmError),
/// Cannot reboot the VM /// Cannot reboot the VM
#[error("Error rebooting VM: {0:?}")]
VmReboot(VmError), VmReboot(VmError),
/// Cannot shut a VM down /// Cannot shut a VM down
#[error("Error shutting down VM: {0:?}")]
VmShutdown(VmError), VmShutdown(VmError),
/// Cannot create VMM thread /// Cannot create VMM thread
VmmThreadSpawn(io::Error), #[error("Error spawning VMM thread {0:?}")]
VmmThreadSpawn(#[source] io::Error),
/// Cannot shut the VMM down /// Cannot shut the VMM down
#[error("Error shutting down VMM: {0:?}")]
VmmShutdown(VmError), VmmShutdown(VmError),
// Error following "exe" link // Error following "exe" link
ExePathReadLink(io::Error), #[error("Error following \"exe\" link: {0}")]
ExePathReadLink(#[source] io::Error),
/// Cannot create seccomp filter /// Cannot create seccomp filter
#[error("Error creating seccomp filter: {0}")]
CreateSeccompFilter(seccomp::SeccompError), CreateSeccompFilter(seccomp::SeccompError),
/// Cannot apply seccomp filter /// Cannot apply seccomp filter
#[error("Error applying seccomp filter: {0}")]
ApplySeccompFilter(seccomp::Error), ApplySeccompFilter(seccomp::Error),
} }
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;