Class: U3d::FailureReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/u3d/failure_reporter.rb

Overview

Internal class to use when trying to improve the prettifier Opt-in with env variable U3D_REPORT_FAILURES

Class Method Summary collapse

Class Method Details

.default_report_pathObject



34
35
36
# File 'lib/u3d/failure_reporter.rb', line 34

def default_report_path
  File.join(U3dCore::Helper.data_path, 'failures')
end

.report(failure_type: "DEFAULT", failure_message: "", data: {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/u3d/failure_reporter.rb', line 12

def report(failure_type: "DEFAULT", failure_message: "", data: {})
  return unless ENV['U3D_REPORT_FAILURES']

  report = {
    type: failure_type,
    message: failure_message,
    data: data
  }

  FileUtils.mkdir_p default_report_path
  report_file = File.join(
    default_report_path,
    "#{failure_type}.#{Date.now.strftime('%Y%m%dT%H%M')}.failure.json"
  )

  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