summary refs log tree commit diff
path: root/devices/src/pit.rs
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-02-12 17:51:26 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-20 08:20:02 -0800
commitb4bd00fdad094b16c785b8ead9f92d68264f5fb4 (patch)
tree540ad033c789aa08a1ffed17e9c161df331600d2 /devices/src/pit.rs
parent0373b9f154b5ec1894138b7c10ad495fcce7b64f (diff)
downloadcrosvm-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/pit.rs')
-rw-r--r--devices/src/pit.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/devices/src/pit.rs b/devices/src/pit.rs
index aa8161f..c01888c 100644
--- a/devices/src/pit.rs
+++ b/devices/src/pit.rs
@@ -161,15 +161,17 @@ pub enum PitError {
 
 impl fmt::Display for PitError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        use self::PitError::*;
+
         match self {
-            PitError::TimerFdCreateError(e) => {
-                write!(f, "failed to create pit counter due to timer fd: {:?}", e)
+            TimerFdCreateError(e) => {
+                write!(f, "failed to create pit counter due to timer fd: {}", e)
             }
-            PitError::CreatePollContext(e) => write!(f, "failed to create poll context: {:?}", e),
-            PitError::PollError(err) => write!(f, "failed to poll events: {:?}", err),
-            PitError::SpawnThread(err) => write!(f, "failed to spawn thread: {:?}", err),
-            PitError::CreateEventFd(err) => write!(f, "failed to create event fd: {:?}", err),
-            PitError::CloneEventFd(err) => write!(f, "failed to clone event fd: {:?}", err),
+            CreatePollContext(e) => write!(f, "failed to create poll context: {}", e),
+            PollError(err) => write!(f, "failed to poll events: {}", err),
+            SpawnThread(err) => write!(f, "failed to spawn thread: {}", err),
+            CreateEventFd(err) => write!(f, "failed to create event fd: {}", err),
+            CloneEventFd(err) => write!(f, "failed to clone event fd: {}", err),
         }
     }
 }
@@ -195,7 +197,7 @@ pub struct Pit {
 impl Drop for Pit {
     fn drop(&mut self) {
         if let Err(e) = self.kill_evt.write(1) {
-            error!("failed to kill PIT worker threads: {:?}", e);
+            error!("failed to kill PIT worker threads: {}", e);
             return;
         }
         if let Some(thread) = self.worker_thread.take() {