@@ -57,7 +57,7 @@ pub fn invoke_get(resource: &ResourceManifest, cwd: &str, filter: &str) -> Resul
57
57
}
58
58
59
59
info ! ( "Invoking get '{}' using '{}'" , & resource. resource_type, & get. executable) ;
60
- let ( _exit_code, stdout, stderr) = invoke_command ( & get. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
60
+ let ( _exit_code, stdout, stderr) = invoke_command ( & get. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
61
61
if resource. kind == Some ( Kind :: Resource ) {
62
62
debug ! ( "Verifying output of get '{}' using '{}'" , & resource. resource_type, & get. executable) ;
63
63
verify_json ( resource, cwd, & stdout) ?;
@@ -142,7 +142,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
142
142
let command_input = get_command_input ( & get. input , desired) ?;
143
143
144
144
info ! ( "Getting current state for set by invoking get {} using {}" , & resource. resource_type, & get. executable) ;
145
- let ( exit_code, stdout, stderr) = invoke_command ( & get. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
145
+ let ( exit_code, stdout, stderr) = invoke_command ( & get. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
146
146
147
147
if resource. kind == Some ( Kind :: Resource ) {
148
148
debug ! ( "Verifying output of get '{}' using '{}'" , & resource. resource_type, & get. executable) ;
@@ -172,7 +172,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
172
172
}
173
173
174
174
info ! ( "Invoking set '{}' using '{}'" , & resource. resource_type, & set. executable) ;
175
- let ( exit_code, stdout, stderr) = invoke_command ( & set. executable , args, input_desired, Some ( cwd) , env) ?;
175
+ let ( exit_code, stdout, stderr) = invoke_command ( & set. executable , args, input_desired, Some ( cwd) , env, & resource . exit_codes ) ?;
176
176
177
177
match set. returns {
178
178
Some ( ReturnKind :: State ) => {
@@ -265,7 +265,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
265
265
let command_input = get_command_input ( & test. input , expected) ?;
266
266
267
267
info ! ( "Invoking test '{}' using '{}'" , & resource. resource_type, & test. executable) ;
268
- let ( exit_code, stdout, stderr) = invoke_command ( & test. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
268
+ let ( exit_code, stdout, stderr) = invoke_command ( & test. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
269
269
270
270
if resource. kind == Some ( Kind :: Resource ) {
271
271
debug ! ( "Verifying output of test '{}' using '{}'" , & resource. resource_type, & test. executable) ;
@@ -379,7 +379,7 @@ pub fn invoke_delete(resource: &ResourceManifest, cwd: &str, filter: &str) -> Re
379
379
let command_input = get_command_input ( & delete. input , filter) ?;
380
380
381
381
info ! ( "Invoking delete '{}' using '{}'" , & resource. resource_type, & delete. executable) ;
382
- let ( _exit_code, _stdout, _stderr) = invoke_command ( & delete. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
382
+ let ( _exit_code, _stdout, _stderr) = invoke_command ( & delete. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
383
383
384
384
Ok ( ( ) )
385
385
}
@@ -410,7 +410,7 @@ pub fn invoke_validate(resource: &ResourceManifest, cwd: &str, config: &str) ->
410
410
let command_input = get_command_input ( & validate. input , config) ?;
411
411
412
412
info ! ( "Invoking validate '{}' using '{}'" , & resource. resource_type, & validate. executable) ;
413
- let ( _exit_code, stdout, _stderr) = invoke_command ( & validate. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
413
+ let ( _exit_code, stdout, _stderr) = invoke_command ( & validate. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
414
414
let result: ValidateResult = serde_json:: from_str ( & stdout) ?;
415
415
Ok ( result)
416
416
}
@@ -431,7 +431,7 @@ pub fn get_schema(resource: &ResourceManifest, cwd: &str) -> Result<String, DscE
431
431
432
432
match schema_kind {
433
433
SchemaKind :: Command ( ref command) => {
434
- let ( _exit_code, stdout, _stderr) = invoke_command ( & command. executable , command. args . clone ( ) , None , Some ( cwd) , None ) ?;
434
+ let ( _exit_code, stdout, _stderr) = invoke_command ( & command. executable , command. args . clone ( ) , None , Some ( cwd) , None , & resource . exit_codes ) ?;
435
435
Ok ( stdout)
436
436
} ,
437
437
SchemaKind :: Embedded ( ref schema) => {
@@ -486,7 +486,7 @@ pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>
486
486
args = process_args ( & export. args , "" ) ;
487
487
}
488
488
489
- let ( _exit_code, stdout, stderr) = invoke_command ( & export. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
489
+ let ( _exit_code, stdout, stderr) = invoke_command ( & export. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
490
490
let mut instances: Vec < Value > = Vec :: new ( ) ;
491
491
for line in stdout. lines ( )
492
492
{
@@ -532,7 +532,7 @@ pub fn invoke_resolve(resource: &ResourceManifest, cwd: &str, input: &str) -> Re
532
532
let command_input = get_command_input ( & resolve. input , input) ?;
533
533
534
534
info ! ( "Invoking resolve '{}' using '{}'" , & resource. resource_type, & resolve. executable) ;
535
- let ( _exit_code, stdout, _stderr) = invoke_command ( & resolve. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
535
+ let ( _exit_code, stdout, _stderr) = invoke_command ( & resolve. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
536
536
let result: ResolveResult = serde_json:: from_str ( & stdout) ?;
537
537
Ok ( result)
538
538
}
@@ -550,7 +550,7 @@ pub fn invoke_resolve(resource: &ResourceManifest, cwd: &str, input: &str) -> Re
550
550
///
551
551
/// Error is returned if the command fails to execute or stdin/stdout/stderr cannot be opened.
552
552
#[ allow( clippy:: implicit_hasher) ]
553
- pub fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & str > , env : Option < HashMap < String , String > > ) -> Result < ( i32 , String , String ) , DscError > {
553
+ pub fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & str > , env : Option < HashMap < String , String > > , exit_codes : & Option < HashMap < i32 , String > > ) -> Result < ( i32 , String , String ) , DscError > {
554
554
debug ! ( "Invoking command '{}' with args {:?}" , executable, args) ;
555
555
let mut command = Command :: new ( executable) ;
556
556
if input. is_some ( ) {
@@ -614,6 +614,11 @@ pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option
614
614
} ;
615
615
616
616
if exit_code != 0 {
617
+ if let Some ( exit_codes) = exit_codes {
618
+ if let Some ( error_message) = exit_codes. get ( & exit_code) {
619
+ return Err ( DscError :: Command ( executable. to_string ( ) , exit_code, error_message. to_string ( ) ) ) ;
620
+ }
621
+ }
617
622
return Err ( DscError :: Command ( executable. to_string ( ) , exit_code, cleaned_stderr) ) ;
618
623
}
619
624
0 commit comments