From dfd0139d7cf2935add342c76cec66702800e95b7 Mon Sep 17 00:00:00 2001 From: "A. Cody Schuffelen" Date: Tue, 25 Feb 2020 11:53:32 -0800 Subject: 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 Tested-by: kokoro Commit-Queue: Cody Schuffelen --- disk/src/composite.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'disk') 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(), -- cgit 1.4.1