From 3a47f83d5316e06ddd1177dc6f29dfa88782808c Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 15 Aug 2024 13:56:24 +0000 Subject: [PATCH] (bug) - fix ignored errormessage ps_managaer.execute call --- .rubocop_todo.yml | 2 +- .../provider/dsc_base_provider/dsc_base_provider.rb | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 11f40c40..1351855f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -56,7 +56,7 @@ Metrics/CyclomaticComplexity: # Offense count: 23 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 42 + Max: 44 # Offense count: 10 # Configuration parameters: AllowedMethods, AllowedPatterns. diff --git a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb index fecaf3c5..b7f04a98 100644 --- a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +++ b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb @@ -261,18 +261,17 @@ def invoke_dsc_resource(context, name_hash, props, method) if output[:stdout].nil? message = 'Nothing returned.' - message += " #{output[:errormessage]}" if output[:errormessage]&.match?(/PowerShell module timeout \(\d+ ms\) exceeded while executing/) context.err(message) return nil end begin - data = JSON.parse(output[:stdout]) + data = JSON.parse(output) rescue StandardError => e context.err(e) return nil end - context.debug("raw data received: #{data.inspect}") + context.debug("raw data received: #{data['stdout'].inspect}") collision_error_matcher = /The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked/ error = data['errormessage'] @@ -289,7 +288,10 @@ def invoke_dsc_resource(context, name_hash, props, method) elsif error.match?(collision_error_matcher) context.notice('Invoke-DscResource collision detected: Please stagger the timing of your Puppet runs as this can lead to unexpected behaviour.') retry_invoke_dsc_resource(context, 5, 60, collision_error_matcher) do - data = ps_manager.execute(remove_secret_identifiers(script_content))[:stdout] + data = JSON.parse(ps_manager.execute(remove_secret_identifiers(script_content))) + rescue StandardError => e + context.err(e) + return nil end else context.err(error) @@ -297,7 +299,7 @@ def invoke_dsc_resource(context, name_hash, props, method) # Either way, something went wrong and we didn't get back a good result, so return nil return nil end - data + data['stdout'] end # Sets the @timeout instance variable.