Skip to content

Commit

Permalink
Merge pull request ManageIQ#23137 from Fryguy/yarn_audit_better_errors
Browse files Browse the repository at this point in the history
Improve error display when yarn audits fail
  • Loading branch information
jrafanie authored Aug 7, 2024
2 parents c1c063b + f5f38ba commit 46c992a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/tasks/test_security_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,18 @@ def self.yarn_audit(format: "human")
cmd = AwesomeSpawn.build_command_line("yarn npm audit", params)
puts "** command: #{cmd}"

system(cmd, options)
system(cmd, options).tap do |audit_success|
# If the run failed due to a configuration error, the error message will appear
# in the json output, but not in json format, so let's detect and display.
if !audit_success && format == "json"
begin
first_line = log_file.read.lines.first.to_s.chomp
JSON.parse(first_line) unless first_line.empty?
rescue JSON::ParserError
$stderr.puts log_file.read
end
end
end
end.all?

raise SecurityTestFailed unless success
Expand Down

0 comments on commit 46c992a

Please sign in to comment.