From f5f38ba47ddc363b921439d1ccb58f6a7600b297 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Wed, 7 Aug 2024 16:06:54 -0400 Subject: [PATCH] Improve error display when yarn audits fail --- lib/tasks/test_security_helper.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tasks/test_security_helper.rb b/lib/tasks/test_security_helper.rb index 72c466f681e..03a424d1eda 100644 --- a/lib/tasks/test_security_helper.rb +++ b/lib/tasks/test_security_helper.rb @@ -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