mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
sys_util: Switch syslog error to thiserror
BUG=none TEST=cargo build Cq-Depend: chromium:2900011 Change-Id: I97d8fcef1b0c381a5adb691813b15dfe534f66e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2894326 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
This commit is contained in:
parent
82cddfef8e
commit
a60ffb8c36
3 changed files with 12 additions and 18 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1051,6 +1051,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"sync",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -9,6 +9,7 @@ include = ["src/**/*", "Cargo.toml"]
|
|||
data_model = { path = "../data_model" } # provided by ebuild
|
||||
libc = "*"
|
||||
poll_token_derive = { version = "*", path = "poll_token_derive" }
|
||||
thiserror = "*"
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
serde_json = "1"
|
||||
sync = { path = "../sync" } # provided by ebuild
|
||||
|
|
|
@ -33,6 +33,7 @@ use std::path::PathBuf;
|
|||
use std::sync::{MutexGuard, Once};
|
||||
|
||||
use sync::Mutex;
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
/// The priority (i.e. severity) of a syslog message.
|
||||
///
|
||||
|
@ -93,37 +94,28 @@ pub enum Facility {
|
|||
}
|
||||
|
||||
/// Errors returned by `syslog::init()`.
|
||||
#[derive(Debug)]
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum Error {
|
||||
/// Initialization was never attempted.
|
||||
#[error("initialization was never attempted")]
|
||||
NeverInitialized,
|
||||
/// Initialization has previously failed and can not be retried.
|
||||
#[error("initialization previously failed and cannot be retried")]
|
||||
Poisoned,
|
||||
/// Error while creating socket.
|
||||
#[error("failed to create socket: {0}")]
|
||||
Socket(io::Error),
|
||||
/// Error while attempting to connect socket.
|
||||
#[error("failed to connect socket: {0}")]
|
||||
Connect(io::Error),
|
||||
// There was an error using `open` to get the lowest file descriptor.
|
||||
/// There was an error using `open` to get the lowest file descriptor.
|
||||
#[error("failed to get lowest file descriptor: {0}")]
|
||||
GetLowestFd(io::Error),
|
||||
// The guess of libc's file descriptor for the syslog connection was invalid.
|
||||
/// The guess of libc's file descriptor for the syslog connection was invalid.
|
||||
#[error("guess of fd for syslog connection was invalid")]
|
||||
InvalidFd,
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Error::*;
|
||||
|
||||
match self {
|
||||
NeverInitialized => write!(f, "initialization was never attempted"),
|
||||
Poisoned => write!(f, "initialization previously failed and cannot be retried"),
|
||||
Socket(e) => write!(f, "failed to create socket: {}", e),
|
||||
Connect(e) => write!(f, "failed to connect socket: {}", e),
|
||||
GetLowestFd(e) => write!(f, "failed to get lowest file descriptor: {}", e),
|
||||
InvalidFd => write!(f, "guess of fd for syslog connection was invalid"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_proc_name() -> Option<String> {
|
||||
env::args_os()
|
||||
.next()
|
||||
|
|
Loading…
Reference in a new issue