| 
									
										
										
										
											2013-02-06 18:46:36 -06:00
										 |  |  | require 'debrew/menu' | 
					
						
							|  |  |  | require 'debrew/raise_plus' | 
					
						
							| 
									
										
										
										
											2014-03-13 10:05:55 -05:00
										 |  |  | require 'set' | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-07 18:58:41 -06:00
										 |  |  | unless ENV['HOMEBREW_NO_READLINE'] | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  |   begin | 
					
						
							|  |  |  |     require 'rubygems' | 
					
						
							|  |  |  |     require 'ruby-debug' | 
					
						
							|  |  |  |   rescue LoadError | 
					
						
							| 
									
										
										
										
											2013-02-07 18:58:41 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   require 'debrew/irb' | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Object | 
					
						
							|  |  |  |   include RaisePlus | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:05:55 -05:00
										 |  |  | module ResourceDebugger | 
					
						
							| 
									
										
										
										
											2014-03-14 12:54:17 -05:00
										 |  |  |   def stage(target=nil, &block) | 
					
						
							| 
									
										
										
										
											2014-03-14 13:03:51 -05:00
										 |  |  |     return super if target | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:05:55 -05:00
										 |  |  |     super do | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         block.call(self) | 
					
						
							|  |  |  |       rescue Exception => e | 
					
						
							|  |  |  |         if ARGV.debug? | 
					
						
							|  |  |  |           debrew e | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           raise | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $debugged_exceptions = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  | def debrew(exception, formula=nil) | 
					
						
							| 
									
										
										
										
											2014-03-13 10:05:55 -05:00
										 |  |  |   raise exception unless $debugged_exceptions.add?(exception) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  |   puts "#{exception.backtrace.first}" | 
					
						
							| 
									
										
										
										
											2014-06-12 16:12:21 -05:00
										 |  |  |   puts "#{Tty.red}#{exception.class.name}#{Tty.reset}: #{exception}" | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   begin | 
					
						
							|  |  |  |     again = false | 
					
						
							|  |  |  |     choose do |menu| | 
					
						
							| 
									
										
										
										
											2012-11-09 15:18:01 -06:00
										 |  |  |       menu.prompt = "Choose an action: " | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  |       menu.choice(:raise) { original_raise exception } | 
					
						
							| 
									
										
										
										
											2014-06-27 15:18:45 -05:00
										 |  |  |       menu.choice(:ignore) { exception.restart } if exception.continuation | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  |       menu.choice(:backtrace) { puts exception.backtrace; again = true } | 
					
						
							|  |  |  |       menu.choice(:debug) do | 
					
						
							|  |  |  |         puts "When you exit the debugger, execution will continue." | 
					
						
							|  |  |  |         exception.restart { debugger } | 
					
						
							| 
									
										
										
										
											2013-02-07 18:58:41 -06:00
										 |  |  |       end if Object.const_defined?(:Debugger) | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  |       menu.choice(:irb) do | 
					
						
							|  |  |  |         puts "When you exit this IRB session, execution will continue." | 
					
						
							|  |  |  |         exception.restart do | 
					
						
							|  |  |  |           # we need to capture the binding after returning from raise | 
					
						
							|  |  |  |           set_trace_func proc { |event, file, line, id, binding, classname| | 
					
						
							|  |  |  |             if event == 'return' | 
					
						
							|  |  |  |               set_trace_func nil | 
					
						
							|  |  |  |               IRB.start_within(binding) | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2014-06-27 15:18:45 -05:00
										 |  |  |       end if Object.const_defined?(:IRB) && exception.continuation | 
					
						
							| 
									
										
										
										
											2012-02-21 01:14:02 -06:00
										 |  |  |       menu.choice(:shell) do | 
					
						
							|  |  |  |         puts "When you exit this shell, you will return to the menu." | 
					
						
							|  |  |  |         interactive_shell formula | 
					
						
							|  |  |  |         again=true | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end while again | 
					
						
							|  |  |  | end |