Skip to content

Commit 1061baa

Browse files
committed
fix: Switch OutputError from Fail
1 parent 1cf53cd commit 1061baa

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/errors.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use std::error::Error;
12
use std::fmt;
23
use std::process;
34
use std::str;
45

5-
use failure;
6-
76
/// `std::process::Output` represented as a `Result`.
87
///
98
/// # Examples
@@ -34,15 +33,15 @@ pub type OutputResult = Result<process::Output, OutputError>;
3433
/// .env("exit", "42")
3534
/// .unwrap_err();
3635
/// ```
37-
#[derive(Fail, Debug)]
36+
#[derive(Debug)]
3837
pub struct OutputError {
3938
cmd: Option<String>,
4039
stdin: Option<Vec<u8>>,
4140
cause: OutputCause,
4241
}
4342

4443
impl OutputError {
45-
/// Convert `std::process::Output` into a `Fail`.
44+
/// Convert `std::process::Output` into an `Error`.
4645
pub fn new(output: process::Output) -> Self {
4746
Self {
4847
cmd: None,
@@ -54,12 +53,12 @@ impl OutputError {
5453
/// For errors that happen in creating a `std::process::Output`.
5554
pub fn with_cause<E>(cause: E) -> Self
5655
where
57-
E: Into<failure::Error>,
56+
E: Error + Send + Sync + 'static,
5857
{
5958
Self {
6059
cmd: None,
6160
stdin: None,
62-
cause: OutputCause::Unexpected(cause.into()),
61+
cause: OutputCause::Unexpected(Box::new(cause)),
6362
}
6463
}
6564

@@ -101,6 +100,19 @@ impl OutputError {
101100
}
102101
}
103102

103+
impl Error for OutputError {
104+
fn description(&self) -> &str {
105+
"Command failed."
106+
}
107+
108+
fn cause(&self) -> Option<&Error> {
109+
if let &OutputCause::Unexpected(ref err) = &self.cause {
110+
Some(err.as_ref())
111+
} else {
112+
None
113+
}
114+
}
115+
}
104116
impl fmt::Display for OutputError {
105117
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
106118
if let Some(ref cmd) = self.cmd {
@@ -120,7 +132,7 @@ impl fmt::Display for OutputError {
120132
#[derive(Debug)]
121133
enum OutputCause {
122134
Expected(Output),
123-
Unexpected(failure::Error),
135+
Unexpected(Box<Error + Send + Sync + 'static>),
124136
}
125137

126138
impl fmt::Display for OutputCause {
@@ -133,7 +145,7 @@ impl fmt::Display for OutputCause {
133145
}
134146

135147
/// Wrap `Output` to be `Dislay`able.
136-
#[derive(Fail, Debug)]
148+
#[derive(Debug)]
137149
struct Output {
138150
output: process::Output,
139151
}

0 commit comments

Comments
 (0)