Skip to content

Commit e545bf9

Browse files
committed
feat: print inner errors
Print inner errors in Display impl of errors. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 69fc3b3 commit e545bf9

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/loader/mod.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,21 @@ pub type Result<T> = std::result::Result<T, Error>;
7575

7676
impl fmt::Display for Error {
7777
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78-
let desc = match self {
78+
write!(f, "Kernel Loader: ")?;
79+
match self {
7980
#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
80-
Error::Bzimage(ref _e) => "failed to load bzImage kernel image",
81+
Error::Bzimage(ref e) => write!(f, "failed to load bzImage kernel image: {e}"),
8182
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
82-
Error::Elf(ref _e) => "failed to load ELF kernel image",
83+
Error::Elf(ref e) => write!(f, "failed to load ELF kernel image: {e}"),
8384
#[cfg(all(feature = "pe", target_arch = "aarch64"))]
84-
Error::Pe(ref _e) => "failed to load PE kernel image",
85-
86-
Error::InvalidCommandLine => "invalid command line provided",
87-
Error::CommandLineCopy => "failed writing command line to guest memory",
88-
Error::CommandLineOverflow => "command line overflowed guest memory",
89-
Error::InvalidKernelStartAddress => "invalid kernel start address",
90-
Error::MemoryOverflow => "memory to load kernel image is not enough",
91-
};
85+
Error::Pe(ref e) => write!(f, "failed to load PE kernel image: {e}"),
9286

93-
write!(f, "Kernel Loader: {}", desc)
87+
Error::InvalidCommandLine => write!(f, "invalid command line provided"),
88+
Error::CommandLineCopy => write!(f, "failed writing command line to guest memory"),
89+
Error::CommandLineOverflow => write!(f, "command line overflowed guest memory"),
90+
Error::InvalidKernelStartAddress => write!(f, "invalid kernel start address"),
91+
Error::MemoryOverflow => write!(f, "memory to load kernel image is not enough"),
92+
}
9493
}
9594
}
9695

0 commit comments

Comments
 (0)