summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-03-04 17:48:36 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-09 22:14:46 -0800
commitbe034264082fd17b7d8f256a51b0753bbd5e8148 (patch)
tree87e4124222af718dd0f64998d946d5bb16821b07 /src/linux.rs
parente54188bf3171b0daf049ba77e12bf6f6eeef689d (diff)
downloadcrosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.tar
crosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.tar.gz
crosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.tar.bz2
crosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.tar.lz
crosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.tar.xz
crosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.tar.zst
crosvm-be034264082fd17b7d8f256a51b0753bbd5e8148.zip
arch: Replace Box<dyn Error> with error enum
Avoiding Box<dyn Error> makes it less likely that we display errors with
insufficient context by accident.

Many of the errors touched in this CL already had helpful message
written! But those corresponding enum variants were never being
instantiated, and that bug was masked by Box<dyn Error>. For example see
the Error::LoadCmdline and Error::LoadKernel.

    pub enum Error {
        LoadCmdline(kernel_loader::Error),
        ...
    }

Before this CL:

    // Bug: boxes the underlying error without adding LoadCmdline
    kernel_loader::load_cmdline(...)?;

After this CL:

    kernel_loader::load_cmdline(...).map_err(Error::LoadCmdline)?;

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

Change-Id: I7c0cff843c2211565226b9dfb4142ad6b7fa15ac
Reviewed-on: https://chromium-review.googlesource.com/1502112
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/linux.rs b/src/linux.rs
index acea1de..a0cb968 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -58,7 +58,7 @@ pub enum Error {
     BalloonDeviceNew(virtio::BalloonError),
     BlockDeviceNew(sys_util::Error),
     BlockSignal(sys_util::signal::Error),
-    BuildingVm(Box<error::Error>),
+    BuildVm(<Arch as LinuxArch>::Error),
     ChownTpmStorage(sys_util::Error),
     CloneEventFd(sys_util::Error),
     CreateCrasClient(libcras::Error),
@@ -123,7 +123,7 @@ impl Display for Error {
             BalloonDeviceNew(e) => write!(f, "failed to create balloon: {}", e),
             BlockDeviceNew(e) => write!(f, "failed to create block device: {}", e),
             BlockSignal(e) => write!(f, "failed to block signal: {}", e),
-            BuildingVm(e) => write!(f, "The architecture failed to build the vm: {}", e),
+            BuildVm(e) => write!(f, "The architecture failed to build the vm: {}", e),
             ChownTpmStorage(e) => write!(f, "failed to chown tpm storage: {}", e),
             CloneEventFd(e) => write!(f, "failed to clone eventfd: {}", e),
             CreateCrasClient(e) => write!(f, "failed to create cras client: {}", e),
@@ -1113,9 +1113,8 @@ pub fn run_config(cfg: Config) -> Result<()> {
             balloon_device_socket,
             &mut disk_device_sockets,
         )
-        .map_err(|e| Box::new(e) as Box<dyn std::error::Error>)
     })
-    .map_err(Error::BuildingVm)?;
+    .map_err(Error::BuildVm)?;
     run_control(
         linux,
         control_server_socket,