Skip to content

Commit 9c494f3

Browse files
committed
have prepare add a generic PrepareError context
if a more specifc one hasn't already been provided this way we can easily distinguish BuildDirectory::run failing due to Prepare::prepare failing from it failing for other reasons
1 parent 8d0a3cb commit 9c494f3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/build.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::cmd::{Command, MountKind, Runnable, SandboxBuilder};
22
use crate::prepare::Prepare;
3-
use crate::{Crate, Toolchain, Workspace};
3+
use crate::{Crate, PrepareError, Toolchain, Workspace};
44
use std::path::PathBuf;
55
use std::vec::Vec;
66

@@ -194,7 +194,13 @@ impl BuildDirectory {
194194
}
195195

196196
let mut prepare = Prepare::new(&self.workspace, toolchain, krate, &source_dir, patches);
197-
prepare.prepare()?;
197+
prepare.prepare().map_err(|err| {
198+
if err.downcast_ref::<PrepareError>().is_none() {
199+
err.context(PrepareError::Unknown)
200+
} else {
201+
err
202+
}
203+
})?;
198204

199205
std::fs::create_dir_all(self.target_dir())?;
200206
let res = f(&Build {

src/prepare.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ pub enum PrepareError {
390390
/// Some of the dependencies do not exist anymore.
391391
#[error("the crate depends on missing dependencies: \n\n{0}")]
392392
MissingDependencies(String),
393+
#[error("prepare failed without further details")]
394+
Unknown,
393395
}
394396

395397
#[cfg(test)]

0 commit comments

Comments
 (0)