Module: Debrew

Extended by:
Mutex_m, Predicable
Defined in:
Library/Homebrew/debrew.rb

Defined Under Namespace

Modules: Formula, Raise Classes: Menu

Constant Summary collapse

Ignorable =
Module.new

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Predicable

attr_predicate

Class Attribute Details

.debugged_exceptionsObject (readonly)

Returns the value of attribute debugged_exceptions



84
85
86
# File 'Library/Homebrew/debrew.rb', line 84

def debugged_exceptions
  @debugged_exceptions
end

Class Method Details

.debrewObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'Library/Homebrew/debrew.rb', line 87

def self.debrew
  @active = true
  Object.send(:include, Raise)

  begin
    yield
  rescue SystemExit
    original_raise
  rescue Exception => e # rubocop:disable Lint/RescueException
    debug(e)
  ensure
    @active = false
  end
end

.debug(e) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'Library/Homebrew/debrew.rb', line 102

def self.debug(e)
  original_raise(e) unless active? &&
                           debugged_exceptions.add?(e) &&
                           try_lock

  begin
    puts e.backtrace.first.to_s
    puts Formatter.error(e, label: e.class.name)

    loop do
      Menu.choose do |menu|
        menu.prompt = "Choose an action: "

        menu.choice(:raise) { original_raise(e) }
        menu.choice(:ignore) { return :ignore } if e.is_a?(Ignorable)
        menu.choice(:backtrace) { puts e.backtrace }

        if e.is_a?(Ignorable)
          menu.choice(:irb) do
            puts "When you exit this IRB session, execution will continue."
            set_trace_func proc { |event, _, _, id, binding, klass| # rubocop:disable Metrics/ParameterLists
              if klass == Raise && id == :raise && event == "return"
                set_trace_func(nil)
                synchronize { IRB.start_within(binding) }
              end
            }

            return :ignore
          end
        end

        menu.choice(:shell) do
          puts "When you exit this shell, you will return to the menu."
          interactive_shell
        end
      end
    end
  ensure
    unlock
  end
end