Module: Utils::Backtrace Private

Defined in:
utils/backtrace.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Class Method Details

.clean(error) ⇒ Array<String>?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Cleans sorbet-runtime gem paths from the backtrace unless...

  1. verbose is set
  2. first backtrace line starts with sorbet-runtime
    • This implies that the error is related to Sorbet.

Parameters:

  • error (Exception)

Returns:



13
14
15
16
17
18
19
20
21
22
23
# File 'utils/backtrace.rb', line 13

def self.clean(error)
  backtrace = error.backtrace

  return backtrace if Context.current.verbose?
  return backtrace if backtrace.blank?
  return backtrace if backtrace.fetch(0).start_with?(sorbet_runtime_path)

  old_backtrace_length = backtrace.length
  backtrace.reject { |line| line.start_with?(sorbet_runtime_path) }
           .tap { |new_backtrace| print_backtrace_message if old_backtrace_length > new_backtrace.length }
end

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



31
32
33
34
35
36
37
38
# File 'utils/backtrace.rb', line 31

def self.print_backtrace_message
  return if @print_backtrace_message

  opoo "Removed Sorbet lines from backtrace!"
  puts "Rerun with `--verbose` to see the original backtrace" unless Homebrew::EnvConfig.no_env_hints?

  @print_backtrace_message = true
end

.sorbet_runtime_pathString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



26
27
28
# File 'utils/backtrace.rb', line 26

def self.sorbet_runtime_path
  @sorbet_runtime_path ||= T.let("#{Gem.paths.home}/gems/sorbet-runtime", T.nilable(String))
end

.tap_error_url(error) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • error (Exception)

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'utils/backtrace.rb', line 41

def self.tap_error_url(error)
  backtrace = error.backtrace
  return if backtrace.blank?

  backtrace.each do |line|
    if (tap = line.match(%r{/Library/Taps/([^/]+/[^/]+)/}))
      return "https://github.com/#{tap[1]}/issues/new"
    end
  end

  nil
end