Module: Utils::Backtrace

Defined in:
utils/backtrace.rb

Class Method Summary collapse

Class Method Details

.clean(error) ⇒ Array<String>?

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:



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

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


27
28
29
30
31
32
33
34
# File 'utils/backtrace.rb', line 27

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_pathObject



23
24
25
# File 'utils/backtrace.rb', line 23

def self.sorbet_runtime_path
  @sorbet_runtime_path ||= "#{Gem.paths.home}/gems/sorbet-runtime"
end