From d4c5af23febb4d5c2fa5d2f2ce8bc9837068dfff Mon Sep 17 00:00:00 2001 From: nikstur Date: Fri, 30 Dec 2022 03:38:57 +0100 Subject: [PATCH] lanzatool: improve error msg for file_size --- rust/lanzatool/src/pe.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/lanzatool/src/pe.rs b/rust/lanzatool/src/pe.rs index d2d0188..2101b43 100644 --- a/rust/lanzatool/src/pe.rs +++ b/rust/lanzatool/src/pe.rs @@ -205,5 +205,13 @@ fn image_base(pe: &PE) -> u64 { } fn file_size(path: impl AsRef) -> Result { - Ok(fs::File::open(path)?.metadata()?.size()) + Ok(fs::File::open(&path) + .with_context(|| { + format!( + "Failed to read file to calculate its size: {:?}", + path.as_ref() + ) + })? + .metadata()? + .size()) }