summary refs log tree commit diff
path: root/devices/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-03-01 18:07:56 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-02 17:41:31 -0800
commitc69f97542a6071f78d48a743ee94119a93bc9471 (patch)
tree69ee27de806bf460c108219d9d2c64bd633cf35d /devices/src
parent5e1b46cbd8cb031a12c0fb20e94670f1007fd789 (diff)
downloadcrosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.gz
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.bz2
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.lz
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.xz
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.zst
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.zip
error: Consistently use Display instead of error description()
The description method is deprecated and its signature forces less
helpful error messages than what Display can provide.

BUG=none
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: I27fc99d59d0ef457c5273dc53e4c563ef439c2c0
Reviewed-on: https://chromium-review.googlesource.com/1497735
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices/src')
-rw-r--r--devices/src/pci/ac97_bus_master.rs2
-rw-r--r--devices/src/pit.rs10
-rw-r--r--devices/src/proxy.rs11
-rw-r--r--devices/src/virtio/p9.rs11
-rw-r--r--devices/src/virtio/wl.rs51
5 files changed, 38 insertions, 47 deletions
diff --git a/devices/src/pci/ac97_bus_master.rs b/devices/src/pci/ac97_bus_master.rs
index b67450e..4ea9097 100644
--- a/devices/src/pci/ac97_bus_master.rs
+++ b/devices/src/pci/ac97_bus_master.rs
@@ -78,7 +78,7 @@ enum PlaybackError {
     WritingOutput(std::io::Error),
 }
 
-impl Error for PlaybackError {}
+impl std::error::Error for PlaybackError {}
 
 impl Display for PlaybackError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
diff --git a/devices/src/pit.rs b/devices/src/pit.rs
index 398ff86..6f508c7 100644
--- a/devices/src/pit.rs
+++ b/devices/src/pit.rs
@@ -3,7 +3,7 @@
 // found in the LICENSE file.
 // Based heavily on GCE VMM's pit.cc.
 
-use std::fmt;
+use std::fmt::{self, Display};
 use std::io::Error as IoError;
 use std::os::unix::io::AsRawFd;
 use std::sync::Arc;
@@ -159,7 +159,7 @@ pub enum PitError {
     CloneEventFd(SysError),
 }
 
-impl fmt::Display for PitError {
+impl Display for PitError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::PitError::*;
 
@@ -176,11 +176,7 @@ impl fmt::Display for PitError {
     }
 }
 
-impl std::error::Error for PitError {
-    fn description(&self) -> &str {
-        "Pit failure"
-    }
-}
+impl std::error::Error for PitError {}
 
 type PitResult<T> = std::result::Result<T, PitError>;
 
diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs
index a91d2ed..e7cc95f 100644
--- a/devices/src/proxy.rs
+++ b/devices/src/proxy.rs
@@ -6,10 +6,11 @@
 
 use libc::pid_t;
 
+use std::fmt::{self, Display};
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::process;
 use std::time::Duration;
-use std::{self, fmt, io};
+use std::{self, io};
 
 use io_jail::{self, Minijail};
 use msg_socket::{MsgOnSocket, MsgReceiver, MsgSender, MsgSocket};
@@ -25,11 +26,13 @@ pub enum Error {
 }
 pub type Result<T> = std::result::Result<T, Error>;
 
-impl fmt::Display for Error {
+impl Display for Error {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        use self::Error::*;
+
         match self {
-            Error::ForkingJail(_) => write!(f, "Failed to fork jail process"),
-            Error::Io(e) => write!(f, "IO error configuring proxy device {}.", e),
+            ForkingJail(e) => write!(f, "Failed to fork jail process: {}", e),
+            Io(e) => write!(f, "IO error configuring proxy device {}.", e),
         }
     }
 }
diff --git a/devices/src/virtio/p9.rs b/devices/src/virtio/p9.rs
index be461a0..636a1dc 100644
--- a/devices/src/virtio/p9.rs
+++ b/devices/src/virtio/p9.rs
@@ -3,8 +3,7 @@
 // found in the LICENSE file.
 
 use std::cmp::min;
-use std::error;
-use std::fmt;
+use std::fmt::{self, Display};
 use std::io::{self, Read, Write};
 use std::iter::Peekable;
 use std::mem;
@@ -52,13 +51,9 @@ pub enum P9Error {
     Internal(io::Error),
 }
 
-impl error::Error for P9Error {
-    fn description(&self) -> &str {
-        "An error occurred in the virtio 9P device"
-    }
-}
+impl std::error::Error for P9Error {}
 
-impl fmt::Display for P9Error {
+impl Display for P9Error {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::P9Error::*;
 
diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs
index 0220d42..a9498fe 100644
--- a/devices/src/virtio/wl.rs
+++ b/devices/src/virtio/wl.rs
@@ -32,9 +32,8 @@ use std::cell::RefCell;
 use std::collections::btree_map::Entry;
 use std::collections::{BTreeMap as Map, BTreeSet as Set, VecDeque};
 use std::convert::From;
-use std::error::{self, Error as StdError};
 use std::ffi::CStr;
-use std::fmt;
+use std::fmt::{self, Display};
 use std::fs::File;
 use std::io::{self, Read, Seek, SeekFrom};
 use std::mem::{size_of, size_of_val};
@@ -442,35 +441,33 @@ enum WlError {
     DmabufSync(io::Error),
 }
 
-impl fmt::Display for WlError {
+impl Display for WlError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "{}", self.description())
-    }
-}
-
-impl error::Error for WlError {
-    fn description(&self) -> &str {
-        match *self {
-            WlError::NewAlloc(_) => "Failed to create shared memory allocation",
-            WlError::NewPipe(_) => "Failed to create pipe",
-            WlError::AllocSetSize(_) => "Failed to set size of shared memory",
-            WlError::SocketConnect(_) => "Failed to connect socket",
-            WlError::SocketNonBlock(_) => "Failed to set socket as non-blocking",
-            WlError::VmControl(_) => "Failed to control parent VM",
-            WlError::VmBadResponse => "Invalid response from parent VM",
-            WlError::CheckedOffset => "Overflow in calculation",
-            WlError::GuestMemory(_) => "Access violation in guest memory",
-            WlError::VolatileMemory(_) => "Access violating in guest volatile memory",
-            WlError::SendVfd(_) => "Failed to send on a socket",
-            WlError::WritePipe(_) => "Failed to write to a pipe",
-            WlError::RecvVfd(_) => "Failed to recv on a socket",
-            WlError::ReadPipe(_) => "Failed to read a pipe",
-            WlError::PollContextAdd(_) => "Failed to listen to FD on poll context",
-            WlError::DmabufSync(_) => "Failed to synchronize DMABuf access",
+        use self::WlError::*;
+
+        match self {
+            NewAlloc(e) => write!(f, "failed to create shared memory allocation: {}", e),
+            NewPipe(e) => write!(f, "failed to create pipe: {}", e),
+            AllocSetSize(e) => write!(f, "failed to set size of shared memory: {}", e),
+            SocketConnect(e) => write!(f, "failed to connect socket: {}", e),
+            SocketNonBlock(e) => write!(f, "failed to set socket as non-blocking: {}", e),
+            VmControl(e) => write!(f, "failed to control parent VM: {}", e),
+            VmBadResponse => write!(f, "invalid response from parent VM"),
+            CheckedOffset => write!(f, "overflow in calculation"),
+            GuestMemory(e) => write!(f, "access violation in guest memory: {}", e),
+            VolatileMemory(e) => write!(f, "access violating in guest volatile memory: {}", e),
+            SendVfd(e) => write!(f, "failed to send on a socket: {}", e),
+            WritePipe(e) => write!(f, "failed to write to a pipe: {}", e),
+            RecvVfd(e) => write!(f, "failed to recv on a socket: {}", e),
+            ReadPipe(e) => write!(f, "failed to read a pipe: {}", e),
+            PollContextAdd(e) => write!(f, "failed to listen to FD on poll context: {}", e),
+            DmabufSync(e) => write!(f, "failed to synchronize DMABuf access: {}", e),
         }
     }
 }
 
+impl std::error::Error for WlError {}
+
 type WlResult<T> = result::Result<T, WlError>;
 
 impl From<GuestMemoryError> for WlError {
@@ -648,7 +645,7 @@ enum WlResp<'a> {
     VfdHup {
         id: u32,
     },
-    Err(Box<error::Error>),
+    Err(Box<std::error::Error>),
     OutOfMemory,
     InvalidId,
     InvalidType,