1
+ use std:: error:: Error ;
1
2
use std:: fmt;
2
3
use std:: process;
3
4
use std:: str;
4
5
5
- use failure;
6
-
7
6
/// `std::process::Output` represented as a `Result`.
8
7
///
9
8
/// # Examples
@@ -34,15 +33,15 @@ pub type OutputResult = Result<process::Output, OutputError>;
34
33
/// .env("exit", "42")
35
34
/// .unwrap_err();
36
35
/// ```
37
- #[ derive( Fail , Debug ) ]
36
+ #[ derive( Debug ) ]
38
37
pub struct OutputError {
39
38
cmd : Option < String > ,
40
39
stdin : Option < Vec < u8 > > ,
41
40
cause : OutputCause ,
42
41
}
43
42
44
43
impl OutputError {
45
- /// Convert `std::process::Output` into a `Fail `.
44
+ /// Convert `std::process::Output` into an `Error `.
46
45
pub fn new ( output : process:: Output ) -> Self {
47
46
Self {
48
47
cmd : None ,
@@ -54,12 +53,12 @@ impl OutputError {
54
53
/// For errors that happen in creating a `std::process::Output`.
55
54
pub fn with_cause < E > ( cause : E ) -> Self
56
55
where
57
- E : Into < failure :: Error > ,
56
+ E : Error + Send + Sync + ' static ,
58
57
{
59
58
Self {
60
59
cmd : None ,
61
60
stdin : None ,
62
- cause : OutputCause :: Unexpected ( cause . into ( ) ) ,
61
+ cause : OutputCause :: Unexpected ( Box :: new ( cause ) ) ,
63
62
}
64
63
}
65
64
@@ -101,6 +100,19 @@ impl OutputError {
101
100
}
102
101
}
103
102
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
+ }
104
116
impl fmt:: Display for OutputError {
105
117
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
106
118
if let Some ( ref cmd) = self . cmd {
@@ -120,7 +132,7 @@ impl fmt::Display for OutputError {
120
132
#[ derive( Debug ) ]
121
133
enum OutputCause {
122
134
Expected ( Output ) ,
123
- Unexpected ( failure :: Error ) ,
135
+ Unexpected ( Box < Error + Send + Sync + ' static > ) ,
124
136
}
125
137
126
138
impl fmt:: Display for OutputCause {
@@ -133,7 +145,7 @@ impl fmt::Display for OutputCause {
133
145
}
134
146
135
147
/// Wrap `Output` to be `Dislay`able.
136
- #[ derive( Fail , Debug ) ]
148
+ #[ derive( Debug ) ]
137
149
struct Output {
138
150
output : process:: Output ,
139
151
}
0 commit comments