Skip to content

Commit 8636fc1

Browse files
committed
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.
1 parent f7c8252 commit 8636fc1

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

xbuild/src/command/build.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ pub fn build(env: &BuildEnv) -> Result<()> {
149149
.package_root()
150150
.join(runtime_lib_path)
151151
.join(target.android_abi().android_abi());
152-
let entries = std::fs::read_dir(abi_dir)?;
152+
let entries = std::fs::read_dir(&abi_dir).with_context(|| {
153+
format!(
154+
"Runtime libraries for current ABI not found at `{}`",
155+
abi_dir.display()
156+
)
157+
})?;
153158
for entry in entries {
154159
let entry = entry?;
155160
let path = entry.path();

xbuild/src/download.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{BuildEnv, Platform};
2-
use anyhow::Result;
2+
use anyhow::{Context as _, Result};
33
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
44
use mvn::Download;
55
use reqwest::blocking::Client;
@@ -115,11 +115,11 @@ impl<'a> DownloadManager<'a> {
115115
}
116116

117117
fn rustup_target(&self, target: &str) -> Result<()> {
118-
let status = Command::new("rustup")
119-
.arg("target")
120-
.arg("add")
121-
.arg(target)
122-
.status()?;
118+
let mut command = Command::new("rustup");
119+
command.arg("target").arg("add").arg(target);
120+
let status = command
121+
.status()
122+
.with_context(|| format!("Failed to run `{:?}`", command))?;
123123
anyhow::ensure!(status.success(), "failure running rustup target add");
124124
Ok(())
125125
}

xcommon/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ pub struct Scaler {
2323

2424
impl Scaler {
2525
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
26-
let img = ImageReader::open(path)?.decode()?;
26+
let path = path.as_ref();
27+
let img = ImageReader::open(path)
28+
.with_context(|| format!("Scaler failed to open image at `{}`", path.display()))?
29+
.decode()?;
2730
let (width, height) = img.dimensions();
2831
anyhow::ensure!(width == height, "expected width == height");
2932
anyhow::ensure!(width >= 512, "expected icon of at least 512x512 px");

0 commit comments

Comments
 (0)