Skip to content

Commit

Permalink
Add missing "path context" for more IO failures
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarijnS95 committed Jan 3, 2025
1 parent f7c8252 commit 379261f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion xbuild/src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion xcommon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub struct Scaler {

impl Scaler {
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
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");
Expand Down

0 comments on commit 379261f

Please sign in to comment.