@@ -146,20 +146,24 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
146146 verify_json ( resource, cwd, & stdout) ?;
147147 }
148148
149- let mut pre_state_map : Map < String , Value > = if exit_code == 0 {
149+ let pre_state_value : Value = if exit_code == 0 {
150150 serde_json:: from_str ( & stdout) ?
151151 }
152152 else {
153153 return Err ( DscError :: Command ( resource. resource_type . clone ( ) , exit_code, stderr) ) ;
154154 } ;
155+ let pre_state = if pre_state_value. is_object ( ) {
156+ let mut pre_state_map: Map < String , Value > = serde_json:: from_value ( pre_state_value) ?;
155157
156- // if the resource is an adapter, then the `get` will return a `result`, but a full `set` expects the before state to be `resources`
157- if resource. kind == Some ( Kind :: Adapter ) && pre_state_map. contains_key ( "result" ) && !pre_state_map. contains_key ( "resources" ) {
158- pre_state_map. insert ( "resources" . to_string ( ) , pre_state_map[ "result" ] . clone ( ) ) ;
159- pre_state_map. remove ( "result" ) ;
160- }
161-
162- let pre_state = serde_json:: to_value ( pre_state_map) ?;
158+ // if the resource is an adapter, then the `get` will return a `result`, but a full `set` expects the before state to be `resources`
159+ if resource. kind == Some ( Kind :: Adapter ) && pre_state_map. contains_key ( "result" ) && !pre_state_map. contains_key ( "resources" ) {
160+ pre_state_map. insert ( "resources" . to_string ( ) , pre_state_map[ "result" ] . clone ( ) ) ;
161+ pre_state_map. remove ( "result" ) ;
162+ }
163+ serde_json:: to_value ( pre_state_map) ?
164+ } else {
165+ pre_state_value
166+ } ;
163167
164168 let mut env: Option < HashMap < String , String > > = None ;
165169 let mut input_desired: Option < & str > = None ;
0 commit comments