@@ -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) ?;
@@ -156,8 +156,8 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
156
156
let args = process_args ( & get. args , desired) ;
157
157
let command_input = get_command_input ( & get. input , desired) ?;
158
158
159
- info ! ( "Getting current state for {} by invoking get '{}' using '{}'" , operation_type , & resource. resource_type, & get. executable) ;
160
- let ( exit_code, stdout, stderr) = invoke_command ( & get. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
159
+ info ! ( "Getting current state for set by invoking get '{}' using '{}'" , & resource. resource_type, & get. executable) ;
160
+ let ( exit_code, stdout, stderr) = invoke_command ( & get. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
161
161
162
162
if resource. kind == Some ( Kind :: Resource ) {
163
163
debug ! ( "Verifying output of get '{}' using '{}'" , & resource. resource_type, & get. executable) ;
@@ -187,7 +187,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
187
187
}
188
188
189
189
info ! ( "Invoking {} '{}' using '{}'" , operation_type, & resource. resource_type, & set. executable) ;
190
- let ( exit_code, stdout, stderr) = invoke_command ( & set. executable , args, input_desired, Some ( cwd) , env) ?;
190
+ let ( exit_code, stdout, stderr) = invoke_command ( & set. executable , args, input_desired, Some ( cwd) , env, & resource . exit_codes ) ?;
191
191
192
192
match set. returns {
193
193
Some ( ReturnKind :: State ) => {
@@ -280,7 +280,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
280
280
let command_input = get_command_input ( & test. input , expected) ?;
281
281
282
282
info ! ( "Invoking test '{}' using '{}'" , & resource. resource_type, & test. executable) ;
283
- let ( exit_code, stdout, stderr) = invoke_command ( & test. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
283
+ let ( exit_code, stdout, stderr) = invoke_command ( & test. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
284
284
285
285
if resource. kind == Some ( Kind :: Resource ) {
286
286
debug ! ( "Verifying output of test '{}' using '{}'" , & resource. resource_type, & test. executable) ;
@@ -394,7 +394,7 @@ pub fn invoke_delete(resource: &ResourceManifest, cwd: &str, filter: &str) -> Re
394
394
let command_input = get_command_input ( & delete. input , filter) ?;
395
395
396
396
info ! ( "Invoking delete '{}' using '{}'" , & resource. resource_type, & delete. executable) ;
397
- let ( _exit_code, _stdout, _stderr) = invoke_command ( & delete. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
397
+ let ( _exit_code, _stdout, _stderr) = invoke_command ( & delete. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
398
398
399
399
Ok ( ( ) )
400
400
}
@@ -425,7 +425,7 @@ pub fn invoke_validate(resource: &ResourceManifest, cwd: &str, config: &str) ->
425
425
let command_input = get_command_input ( & validate. input , config) ?;
426
426
427
427
info ! ( "Invoking validate '{}' using '{}'" , & resource. resource_type, & validate. executable) ;
428
- let ( _exit_code, stdout, _stderr) = invoke_command ( & validate. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
428
+ let ( _exit_code, stdout, _stderr) = invoke_command ( & validate. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
429
429
let result: ValidateResult = serde_json:: from_str ( & stdout) ?;
430
430
Ok ( result)
431
431
}
@@ -446,7 +446,7 @@ pub fn get_schema(resource: &ResourceManifest, cwd: &str) -> Result<String, DscE
446
446
447
447
match schema_kind {
448
448
SchemaKind :: Command ( ref command) => {
449
- let ( _exit_code, stdout, _stderr) = invoke_command ( & command. executable , command. args . clone ( ) , None , Some ( cwd) , None ) ?;
449
+ let ( _exit_code, stdout, _stderr) = invoke_command ( & command. executable , command. args . clone ( ) , None , Some ( cwd) , None , & resource . exit_codes ) ?;
450
450
Ok ( stdout)
451
451
} ,
452
452
SchemaKind :: Embedded ( ref schema) => {
@@ -501,7 +501,7 @@ pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>
501
501
args = process_args ( & export. args , "" ) ;
502
502
}
503
503
504
- let ( _exit_code, stdout, stderr) = invoke_command ( & export. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
504
+ let ( _exit_code, stdout, stderr) = invoke_command ( & export. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
505
505
let mut instances: Vec < Value > = Vec :: new ( ) ;
506
506
for line in stdout. lines ( )
507
507
{
@@ -547,7 +547,7 @@ pub fn invoke_resolve(resource: &ResourceManifest, cwd: &str, input: &str) -> Re
547
547
let command_input = get_command_input ( & resolve. input , input) ?;
548
548
549
549
info ! ( "Invoking resolve '{}' using '{}'" , & resource. resource_type, & resolve. executable) ;
550
- let ( _exit_code, stdout, _stderr) = invoke_command ( & resolve. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
550
+ let ( _exit_code, stdout, _stderr) = invoke_command ( & resolve. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env , & resource . exit_codes ) ?;
551
551
let result: ResolveResult = serde_json:: from_str ( & stdout) ?;
552
552
Ok ( result)
553
553
}
@@ -565,7 +565,7 @@ pub fn invoke_resolve(resource: &ResourceManifest, cwd: &str, input: &str) -> Re
565
565
///
566
566
/// Error is returned if the command fails to execute or stdin/stdout/stderr cannot be opened.
567
567
#[ allow( clippy:: implicit_hasher) ]
568
- 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 > {
568
+ 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 > {
569
569
debug ! ( "Invoking command '{}' with args {:?}" , executable, args) ;
570
570
let mut command = Command :: new ( executable) ;
571
571
if input. is_some ( ) {
@@ -629,6 +629,11 @@ pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option
629
629
} ;
630
630
631
631
if exit_code != 0 {
632
+ if let Some ( exit_codes) = exit_codes {
633
+ if let Some ( error_message) = exit_codes. get ( & exit_code) {
634
+ return Err ( DscError :: CommandExitFromManifest ( executable. to_string ( ) , exit_code, error_message. to_string ( ) ) ) ;
635
+ }
636
+ }
632
637
return Err ( DscError :: Command ( executable. to_string ( ) , exit_code, cleaned_stderr) ) ;
633
638
}
634
639
0 commit comments