summary refs log tree commit diff
path: root/disk
diff options
context:
space:
mode:
authorA. Cody Schuffelen <schuffelen@google.com>2020-02-25 11:53:32 -0800
committerCommit Bot <commit-bot@chromium.org>2020-02-26 02:23:10 +0000
commitdfd0139d7cf2935add342c76cec66702800e95b7 (patch)
tree51f1ea83d7a13f669a785110b304c8dd0d048ca3 /disk
parentf1f20f59be90ae38b859aee0d3bf26f44c33a40d (diff)
downloadcrosvm-dfd0139d7cf2935add342c76cec66702800e95b7.tar
crosvm-dfd0139d7cf2935add342c76cec66702800e95b7.tar.gz
crosvm-dfd0139d7cf2935add342c76cec66702800e95b7.tar.bz2
crosvm-dfd0139d7cf2935add342c76cec66702800e95b7.tar.lz
crosvm-dfd0139d7cf2935add342c76cec66702800e95b7.tar.xz
crosvm-dfd0139d7cf2935add342c76cec66702800e95b7.tar.zst
crosvm-dfd0139d7cf2935add342c76cec66702800e95b7.zip
Better errors on missing composite disk components.
When there is an error opening one of the composite disk components now,
it gives the message `failed to open component file: "No such file or
directory (os error 2)"` without specifying the file path it tried to
use. Exposing the file path will make it faster to act on errors, rather
than trying to examine the composite disk file for paths.

TEST=n/a
BUG=b:150150052

Change-Id: I9341b330e7e6dcd517d5bfb5262b1657a2da46fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2072738
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Diffstat (limited to 'disk')
-rw-r--r--disk/src/composite.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/disk/src/composite.rs b/disk/src/composite.rs
index cd048c1..e95c8e9 100644
--- a/disk/src/composite.rs
+++ b/disk/src/composite.rs
@@ -24,7 +24,7 @@ pub enum Error {
     InvalidMagicHeader,
     InvalidProto(protobuf::ProtobufError),
     InvalidSpecification(String),
-    OpenFile(io::Error),
+    OpenFile(io::Error, String),
     ReadSpecificationError(io::Error),
     UnknownVersion(u64),
     UnsupportedComponent(ImageType),
@@ -41,7 +41,7 @@ impl Display for Error {
             InvalidMagicHeader => write!(f, "invalid magic header for composite disk format"),
             InvalidProto(e) => write!(f, "failed to parse specification proto: \"{}\"", e),
             InvalidSpecification(s) => write!(f, "invalid specification: \"{}\"", s),
-            OpenFile(e) => write!(f, "failed to open component file: \"{}\"", e),
+            OpenFile(e, p) => write!(f, "failed to open component file \"{}\": \"{}\"", p, e),
             ReadSpecificationError(e) => write!(f, "failed to read specification: \"{}\"", e),
             UnknownVersion(v) => write!(f, "unknown version {} in specification", v),
             UnsupportedComponent(c) => write!(f, "unsupported component disk type \"{:?}\"", c),
@@ -142,7 +142,7 @@ impl CompositeDiskFile {
                 );
                 let file = open_options
                     .open(disk.get_file_path())
-                    .map_err(Error::OpenFile)?;
+                    .map_err(|e| Error::OpenFile(e, disk.get_file_path().to_string()))?;
                 Ok(ComponentDiskPart {
                     file: create_disk_file(file).map_err(|e| Error::DiskError(Box::new(e)))?,
                     offset: disk.get_offset(),