Skip to content

Commit

Permalink
(bug) - fix ignored errormessage ps_managaer.execute call
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Aug 15, 2024
1 parent a6dd0f0 commit 3a47f83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -289,15 +288,18 @@ 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)
end
# 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.
Expand Down

0 comments on commit 3a47f83

Please sign in to comment.