@@ -7,7 +7,7 @@ use rust_i18n::t;
77use serde:: Deserialize ;
88use serde_json:: { Map , Value } ;
99use std:: { collections:: HashMap , env, path:: { Path , PathBuf } , process:: Stdio } ;
10- use crate :: { configure:: { config_doc:: ExecutionKind , config_result:: { ResourceGetResult , ResourceTestResult } } , types:: FullyQualifiedTypeName , util:: canonicalize_which} ;
10+ use crate :: { configure:: { config_doc:: ExecutionKind , config_result:: { ResourceGetResult , ResourceTestResult } } , types:: { ExitCodesMap , FullyQualifiedTypeName } , util:: canonicalize_which} ;
1111use crate :: dscerror:: DscError ;
1212use super :: { dscresource:: { get_diff, redact, DscResource } , invoke_result:: { ExportResult , GetResult , ResolveResult , SetResult , TestResult , ValidateResult , ResourceGetResponse , ResourceSetResponse , ResourceTestResponse , get_in_desired_state} , resource_manifest:: { GetArgKind , SetDeleteArgKind , InputKind , Kind , ReturnKind , SchemaKind } } ;
1313use tracing:: { error, warn, info, debug, trace} ;
@@ -733,7 +733,7 @@ pub fn invoke_resolve(resource: &DscResource, input: &str) -> Result<ResolveResu
733733///
734734/// Error is returned if the command fails to execute or stdin/stdout/stderr cannot be opened.
735735///
736- async fn run_process_async ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & Path > , env : Option < HashMap < String , String > > , exit_codes : Option < & HashMap < i32 , String > > ) -> Result < ( i32 , String , String ) , DscError > {
736+ async fn run_process_async ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & Path > , env : Option < HashMap < String , String > > , exit_codes : & ExitCodesMap ) -> Result < ( i32 , String , String ) , DscError > {
737737
738738 // use somewhat large initial buffer to avoid early string reallocations;
739739 // the value is based on list result of largest of built-in adapters - WMI adapter ~500KB
@@ -823,10 +823,8 @@ async fn run_process_async(executable: &str, args: Option<Vec<String>>, input: O
823823 debug ! ( "{}" , t!( "dscresources.commandResource.processChildExit" , executable = executable, id = child_id, code = code) ) ;
824824
825825 if code != 0 {
826- if let Some ( exit_codes) = exit_codes {
827- if let Some ( error_message) = exit_codes. get ( & code) {
828- return Err ( DscError :: CommandExitFromManifest ( executable. to_string ( ) , code, error_message. to_string ( ) ) ) ;
829- }
826+ if let Some ( error_message) = exit_codes. get_code ( code) {
827+ return Err ( DscError :: CommandExitFromManifest ( executable. to_string ( ) , code, error_message. clone ( ) ) ) ;
830828 }
831829 return Err ( DscError :: Command ( executable. to_string ( ) , code, stderr_result) ) ;
832830 }
@@ -838,22 +836,6 @@ async fn run_process_async(executable: &str, args: Option<Vec<String>>, input: O
838836 }
839837}
840838
841- fn convert_hashmap_string_keys_to_i32 ( input : Option < & HashMap < String , String > > ) -> Result < Option < HashMap < i32 , String > > , DscError > {
842- if input. is_none ( ) {
843- return Ok ( None ) ;
844- }
845-
846- let mut output: HashMap < i32 , String > = HashMap :: new ( ) ;
847- for ( key, value) in input. unwrap ( ) {
848- if let Ok ( key_int) = key. parse :: < i32 > ( ) {
849- output. insert ( key_int, value. clone ( ) ) ;
850- } else {
851- return Err ( DscError :: NotSupported ( t ! ( "util.invalidExitCodeKey" , key = key) . to_string ( ) ) ) ;
852- }
853- }
854- Ok ( Some ( output) )
855- }
856-
857839/// Invoke a command and return the exit code, stdout, and stderr.
858840///
859841/// # Arguments
@@ -874,8 +856,7 @@ fn convert_hashmap_string_keys_to_i32(input: Option<&HashMap<String, String>>) -
874856/// Will panic if tokio runtime can't be created.
875857///
876858#[ allow( clippy:: implicit_hasher) ]
877- pub fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & Path > , env : Option < HashMap < String , String > > , exit_codes : Option < & HashMap < String , String > > ) -> Result < ( i32 , String , String ) , DscError > {
878- let exit_codes = convert_hashmap_string_keys_to_i32 ( exit_codes) ?;
859+ pub fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & Path > , env : Option < HashMap < String , String > > , exit_codes : & ExitCodesMap ) -> Result < ( i32 , String , String ) , DscError > {
879860 let executable = canonicalize_which ( executable, cwd) ?;
880861
881862 let run_async = async {
@@ -884,7 +865,7 @@ pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option
884865 trace ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd. display( ) ) ) ;
885866 }
886867
887- match run_process_async ( & executable, args, input, cwd, env, exit_codes. as_ref ( ) ) . await {
868+ match run_process_async ( & executable, args, input, cwd, env, exit_codes) . await {
888869 Ok ( ( code, stdout, stderr) ) => {
889870 Ok ( ( code, stdout, stderr) )
890871 } ,
0 commit comments