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 8636fc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 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
12 changes: 6 additions & 6 deletions xbuild/src/download.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{BuildEnv, Platform};
use anyhow::Result;
use anyhow::{Context as _, Result};
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
use mvn::Download;
use reqwest::blocking::Client;
Expand Down Expand Up @@ -115,11 +115,11 @@ impl<'a> DownloadManager<'a> {
}

fn rustup_target(&self, target: &str) -> Result<()> {
let status = Command::new("rustup")
.arg("target")
.arg("add")
.arg(target)
.status()?;
let mut command = Command::new("rustup");
command.arg("target").arg("add").arg(target);
let status = command
.status()
.with_context(|| format!("Failed to run `{:?}`", command))?;
anyhow::ensure!(status.success(), "failure running rustup target add");
Ok(())
}
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 8636fc1

Please sign in to comment.