From b7dd0e156e5ca1c7eebd68dfb1dc9e7ec5e4700e Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 13 Jun 2024 14:10:08 +0200 Subject: [PATCH] Add missing "path context" for more IO failures Whenever a _user configurable_ path is not found, this currently prints a useless "File not found" without any additional context _which_ path was attempted nor where it was configured. By explaining what we're doing in the error messages, users are more likely to know what and where to correct. --- xbuild/src/command/build.rs | 7 ++++++- xcommon/src/lib.rs | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/xbuild/src/command/build.rs b/xbuild/src/command/build.rs index 9e7020f7..e2bbf981 100644 --- a/xbuild/src/command/build.rs +++ b/xbuild/src/command/build.rs @@ -149,7 +149,12 @@ pub fn build(env: &BuildEnv) -> Result<()> { .package_root() .join(runtime_lib_path) .join(target.android_abi().android_abi()); - let entries = std::fs::read_dir(abi_dir)?; + let entries = std::fs::read_dir(&abi_dir).with_context(|| { + format!( + "Runtime libraries for current ABI not found at `{}`", + abi_dir.display() + ) + })?; for entry in entries { let entry = entry?; let path = entry.path(); diff --git a/xcommon/src/lib.rs b/xcommon/src/lib.rs index 4a3ea7f3..cd7093ae 100644 --- a/xcommon/src/lib.rs +++ b/xcommon/src/lib.rs @@ -23,7 +23,10 @@ pub struct Scaler { impl Scaler { pub fn open>(path: P) -> Result { - let img = ImageReader::open(path)?.decode()?; + let path = path.as_ref(); + let img = ImageReader::open(path) + .with_context(|| format!("Scaler failed to open image at `{}`", path.display()))? + .decode()?; let (width, height) = img.dimensions(); anyhow::ensure!(width == height, "expected width == height"); anyhow::ensure!(width >= 512, "expected icon of at least 512x512 px");