@@ -16,7 +16,9 @@ pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Resul
16
16
if output. status . success ( ) {
17
17
Ok ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
18
18
} else {
19
- Err ( crate :: Error :: Command ( String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ) . into ( ) )
19
+ Err ( crate :: Error :: Command (
20
+ String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ,
21
+ ) )
20
22
}
21
23
}
22
24
@@ -32,7 +34,9 @@ pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Resul
32
34
if output. status . success ( ) {
33
35
Ok ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
34
36
} else {
35
- Err ( crate :: Error :: Command ( String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ) . into ( ) )
37
+ Err ( crate :: Error :: Command (
38
+ String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ,
39
+ ) )
36
40
}
37
41
}
38
42
@@ -41,7 +45,9 @@ pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Resul
41
45
pub fn command_path ( command : String ) -> crate :: Result < String > {
42
46
match std:: env:: current_exe ( ) ?. parent ( ) {
43
47
Some ( exe_dir) => Ok ( format ! ( "{}/{}" , exe_dir. display( ) . to_string( ) , command) ) ,
44
- None => Err ( crate :: Error :: Command ( "Could not evaluate executable dir" . to_string ( ) ) . into ( ) ) ,
48
+ None => Err ( crate :: Error :: Command (
49
+ "Could not evaluate executable dir" . to_string ( ) ,
50
+ ) ) ,
45
51
}
46
52
}
47
53
@@ -50,7 +56,9 @@ pub fn command_path(command: String) -> crate::Result<String> {
50
56
pub fn command_path ( command : String ) -> crate :: Result < String > {
51
57
match std:: env:: current_exe ( ) ?. parent ( ) {
52
58
Some ( exe_dir) => Ok ( format ! ( "{}/{}.exe" , exe_dir. display( ) . to_string( ) , command) ) ,
53
- None => Err ( crate :: Error :: Command ( "Could not evaluate executable dir" . to_string ( ) ) . into ( ) ) ,
59
+ None => Err ( crate :: Error :: Command (
60
+ "Could not evaluate executable dir" . to_string ( ) ,
61
+ ) ) ,
54
62
}
55
63
}
56
64
@@ -86,14 +94,17 @@ pub fn spawn_relative_command(
86
94
87
95
/// Gets the binary command with the current target triple.
88
96
pub fn binary_command ( binary_name : String ) -> crate :: Result < String > {
89
- Ok ( format ! ( "{}-{}" , binary_name, platform:: target_triple( ) ?) )
97
+ Ok ( format ! (
98
+ "{}-{}" ,
99
+ binary_name,
100
+ platform:: target_triple( ) . map_err( |e| crate :: Error :: FailedToDetectPlatform ( e. to_string( ) ) ) ?
101
+ ) )
90
102
}
91
103
92
104
// tests for the commands functions.
93
105
#[ cfg( test) ]
94
106
mod test {
95
107
use super :: * ;
96
- use std:: io;
97
108
98
109
#[ cfg( not( windows) ) ]
99
110
#[ test]
@@ -131,7 +142,7 @@ mod test {
131
142
assert ! ( res. is_err( ) ) ;
132
143
133
144
// destruct the Error to check the ErrorKind and test that it is a Command type.
134
- if let Some ( Error :: Command ( e) ) = res. unwrap_err ( ) . downcast_ref :: < Error > ( ) {
145
+ if let Error :: Command ( e) = res. unwrap_err ( ) {
135
146
// assert that the message in the error matches this string.
136
147
assert_eq ! ( * e, "cat: test/: Is a directory\n " . to_string( ) ) ;
137
148
}
@@ -163,7 +174,7 @@ mod test {
163
174
assert ! ( res. is_err( ) ) ;
164
175
165
176
// after asserting that the result is an error, check that the error kind is ErrorKind::Io
166
- if let Some ( s) = res. unwrap_err ( ) . downcast_ref :: < io :: Error > ( ) {
177
+ if let crate :: Error :: Io ( s) = res. unwrap_err ( ) {
167
178
// assert that the ErrorKind inside of the ErrorKind Io is ErrorKind::NotFound
168
179
assert_eq ! ( s. kind( ) , std:: io:: ErrorKind :: NotFound ) ;
169
180
}
0 commit comments