lib/u3d/failure_reporter.rb in u3d-1.2.3 vs lib/u3d/failure_reporter.rb in u3d-1.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'date' require 'fileutils' require 'json' module U3d @@ -7,10 +9,11 @@ # Opt-in with env variable U3D_REPORT_FAILURES class FailureReporter class << self def report(failure_type: "DEFAULT", failure_message: "", data: {}) return unless ENV['U3D_REPORT_FAILURES'] + report = { type: failure_type, message: failure_message, data: data } @@ -19,12 +22,10 @@ report_file = File.join( default_report_path, "#{failure_type}.#{Date.now.strftime('%Y%m%dT%H%M')}.failure.json" ) - File.open(report_file, 'w') do |file| - file.write JSON.pretty_generate(report) - end + File.write(report_file, JSON.pretty_generate(report)) rescue StandardError => e UI.important "Unable to report a #{failure_type} failure. Please use --verbose to get more information about the failure" UI.verbose "Unable to report failure: #{e}" UI.verbose "Failure was: [#{failure_type}]: #{failure_message}" end