Module: ShopifyCLI::ExceptionReporter

Defined in:
lib/shopify_cli/exception_reporter.rb

Class Method Summary collapse

Class Method Details

.report(error, _logs = nil, _api_key = nil, custom_metadata = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shopify_cli/exception_reporter.rb', line 8

def self.report(error, _logs = nil, _api_key = nil,  = {})
  context = ShopifyCLI::Context.new
  unless ShopifyCLI::Environment.development?
    context.puts(context.message("core.error_reporting.unhandled_error.message"))
    context.puts(context.message("core.error_reporting.unhandled_error.issue_message",
      ShopifyCLI::GitHub::IssueURLGenerator.error_url(error)))
  end

  # Stack trace hint
  unless ShopifyCLI::Environment.print_stacktrace?
    context.puts(context.message("core.error_reporting.unhandled_error.stacktrace_message",
      "#{ShopifyCLI::Constants::EnvironmentVariables::STACKTRACE}=1"))
  end

  context.puts("\n")

  return unless reportable_error?(error)

  return unless report?(context: context)
  report_to_bugsnag(error: error, custom_metadata: )
end

.report?(context:) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shopify_cli/exception_reporter.rb', line 53

def self.report?(context:)
  return true if ReportingConfigurationController.reporting_prompted? &&
    ReportingConfigurationController.check_or_prompt_report_automatically(source: :uncaught_error)

  report_error = report_error?(context: context)

  unless ReportingConfigurationController.reporting_prompted?
    ReportingConfigurationController.check_or_prompt_report_automatically(source: :uncaught_error)
  end
  report_error
end

.report_error?(context:) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
# File 'lib/shopify_cli/exception_reporter.rb', line 65

def self.report_error?(context:)
  return false if Environment.development?

  CLI::UI::Prompt.ask(context.message("core.error_reporting.report_error.question")) do |handler|
    handler.option(context.message("core.error_reporting.report_error.yes")) { |_| true }
    handler.option(context.message("core.error_reporting.report_error.no")) { |_| false }
  end
end

.report_error_silently(error) ⇒ Object



3
4
5
6
# File 'lib/shopify_cli/exception_reporter.rb', line 3

def self.report_error_silently(error)
  return unless ReportingConfigurationController.reporting_enabled?
  report_to_bugsnag(error: error)
end

.report_to_bugsnag(error:, custom_metadata: {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shopify_cli/exception_reporter.rb', line 30

def self.report_to_bugsnag(error:, custom_metadata: {})
  ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"] = "1"
  require "bugsnag"

  Bugsnag.configure do |config|
    config.logger.level = ::Logger::ERROR
    config.api_key = ShopifyCLI::Constants::Bugsnag::API_KEY
    config.app_type = "shopify"
    config.project_root = File.expand_path("../../..", __FILE__)
    config.app_version = ShopifyCLI::VERSION
    config.auto_capture_sessions = false
  end

   = { rubyPlatform: RUBY_PLATFORM }
  .merge!()

  Bugsnag.notify(error) do |event|
    event.(:device, )
  end
rescue
  nil
end

.reportable_error?(error) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/shopify_cli/exception_reporter.rb', line 74

def self.reportable_error?(error)
  is_abort = error.is_a?(ShopifyCLI::Abort) || error.is_a?(ShopifyCLI::AbortSilent)
  !is_abort
end