}
}
+ fn with_cause<E: CargoError>(self, cause: E) -> Box<CargoError> {
+ let mut concrete = self.concrete();
+ concrete.cause = Some(cause.box_error());
+ box concrete as Box<CargoError>
+ }
+
fn mark_human(self) -> Box<CargoError> {
let mut concrete = self.concrete();
concrete.is_human = true;
impl<T, E: CargoError> ChainError<T> for Result<T, E> {
fn chain_error<E: CargoError>(self, callback: || -> E) -> CargoResult<T> {
self.map_err(|err| {
- let mut update = callback().concrete();
- update.cause = Some(err.box_error());
- box update as Box<CargoError>
+ callback().with_cause(err)
})
}
}
fn cause<'a>(&'a self) -> Option<&'a CargoError> {
self.cause.as_ref().map(|c| { let err: &CargoError = *c; err })
}
+
+ fn with_cause<E: CargoError>(mut self, err: E) -> Box<CargoError> {
+ self.cause = Some(err.box_error());
+ box self as Box<CargoError>
+ }
}
pub struct ConcreteCargoError {
self.cause.as_ref().map(|c| { let err: &CargoError = *c; err })
}
+ fn with_cause<E: CargoError>(mut self, err: E) -> Box<CargoError> {
+ self.cause = Some(err.box_error());
+ box self as Box<CargoError>
+ }
+
fn is_human(&self) -> bool {
self.is_human
}
let error = if error.is_human() {
error
} else {
- chain(error, human("An unknown error occurred"))
+ human("An unknown error occurred").with_cause(error)
};
CliError { error: error, exit_code: code }
is_human: true
} as Box<CargoError>
}
-
-pub fn chain<E: CargoError>(original: Box<CargoError>, update: E) -> Box<CargoError> {
- let mut concrete = update.concrete();
- concrete.cause = Some(original);
- box concrete as Box<CargoError>
-}
pub use self::process_builder::{process,ProcessBuilder};
pub use self::result::{Wrap, Require};
pub use self::errors::{CargoResult, CargoError, BoxError, ChainError, CliResult, CliError, ProcessError};
-pub use self::errors::{process_error, internal_error, internal, human, chain};
+pub use self::errors::{process_error, internal_error, internal, human};
pub use self::paths::realpath;
pub mod graph;
-use util::errors::{CargoResult, CargoError, chain};
+use util::errors::{CargoResult, CargoError};
pub trait Wrap {
fn wrap<E: CargoError>(self, error: E) -> Self;
fn wrap<E: CargoError>(self, error: E) -> CargoResult<T> {
match self {
Ok(x) => Ok(x),
- Err(e) => Err(chain(e, error))
+ Err(e) => Err(error.with_cause(e))
}
}
}