diff options
author | David Tolnay <dtolnay@chromium.org> | 2019-02-12 17:51:26 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-20 08:20:02 -0800 |
commit | b4bd00fdad094b16c785b8ead9f92d68264f5fb4 (patch) | |
tree | 540ad033c789aa08a1ffed17e9c161df331600d2 /devices/src/virtio/rng.rs | |
parent | 0373b9f154b5ec1894138b7c10ad495fcce7b64f (diff) | |
download | crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.gz crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.bz2 crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.lz crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.xz crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.zst crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.zip |
error: Print errors using Display impl
I have been running into Debug-printed error messages too often and needing to look up in the source code each level of nested errors to find out from the comment on the error variant what the short name of the variant means in human terms. Worse, many errors (like the one shown below) already had error strings written but were being printed from the calling code in the less helpful Debug representation anyway. Before: [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty After: [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices. TEST=cargo check --all-features TEST=FEATURES=test emerge-amd64-generic crosvm Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10 Reviewed-on: https://chromium-review.googlesource.com/1469225 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'devices/src/virtio/rng.rs')
-rw-r--r-- | devices/src/virtio/rng.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/devices/src/virtio/rng.rs b/devices/src/virtio/rng.rs index 96d0d4f..7b3d9f7 100644 --- a/devices/src/virtio/rng.rs +++ b/devices/src/virtio/rng.rs @@ -3,6 +3,7 @@ // found in the LICENSE file. use std; +use std::fmt::{self, Display}; use std::fs::File; use std::io; use std::os::unix::io::{AsRawFd, RawFd}; @@ -24,6 +25,16 @@ pub enum RngError { } pub type Result<T> = std::result::Result<T, RngError>; +impl Display for RngError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::RngError::*; + + match self { + AccessingRandomDev(e) => write!(f, "failed to access /dev/urandom: {}", e), + } + } +} + struct Worker { queue: Queue, mem: GuestMemory, @@ -92,7 +103,7 @@ impl Worker { { Ok(pc) => pc, Err(e) => { - error!("failed creating PollContext: {:?}", e); + error!("failed creating PollContext: {}", e); return; } }; @@ -101,7 +112,7 @@ impl Worker { let events = match poll_ctx.wait() { Ok(v) => v, Err(e) => { - error!("failed polling for events: {:?}", e); + error!("failed polling for events: {}", e); break; } }; @@ -111,7 +122,7 @@ impl Worker { match event.token() { Token::QueueAvailable => { if let Err(e) = queue_evt.read() { - error!("failed reading queue EventFd: {:?}", e); + error!("failed reading queue EventFd: {}", e); break 'poll; } needs_interrupt |= self.process_queue(); @@ -193,7 +204,7 @@ impl VirtioDevice for Rng { let (self_kill_evt, kill_evt) = match EventFd::new().and_then(|e| Ok((e.try_clone()?, e))) { Ok(v) => v, Err(e) => { - error!("failed to create kill EventFd pair: {:?}", e); + error!("failed to create kill EventFd pair: {}", e); return; } }; |