Exception: Exception
- Defined in:
- lib/active_support/dependencies.rb,
lib/active_support/core_ext/exception.rb
Overview
Add file-blaming to exceptions
Constant Summary collapse
- TraceSubstitutions =
[]
- FrameworkRegexp =
/generated_code|vendor|dispatch|ruby|script\/\w+/
Instance Method Summary collapse
- #application_backtrace ⇒ Object
-
#blame_file!(file) ⇒ Object
:nodoc:.
- #blamed_files ⇒ Object
- #clean_backtrace ⇒ Object
- #copy_blame!(exc) ⇒ Object
- #describe_blame ⇒ Object
- #framework_backtrace ⇒ Object
Instance Method Details
#application_backtrace ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/active_support/core_ext/exception.rb', line 16 def application_backtrace before_application_frame = true clean_backtrace.reject do |line| non_app_frame = !! (line =~ FrameworkRegexp) before_application_frame = false unless non_app_frame non_app_frame && ! before_application_frame end end |
#blame_file!(file) ⇒ Object
:nodoc:
222 223 224 |
# File 'lib/active_support/dependencies.rb', line 222 def blame_file!(file) (@blamed_files ||= []).unshift file end |
#blamed_files ⇒ Object
226 227 228 |
# File 'lib/active_support/dependencies.rb', line 226 def blamed_files @blamed_files ||= [] end |
#clean_backtrace ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/active_support/core_ext/exception.rb', line 8 def clean_backtrace backtrace.collect do |line| TraceSubstitutions.inject(line) do |line, (regexp, sub)| line.gsub regexp, sub end end end |
#copy_blame!(exc) ⇒ Object
235 236 237 238 |
# File 'lib/active_support/dependencies.rb', line 235 def copy_blame!(exc) @blamed_files = exc.blamed_files.clone self end |
#describe_blame ⇒ Object
230 231 232 233 |
# File 'lib/active_support/dependencies.rb', line 230 def describe_blame return nil if blamed_files.empty? "This error occured while loading the following files:\n #{blamed_files.join "\n "}" end |
#framework_backtrace ⇒ Object
26 27 28 |
# File 'lib/active_support/core_ext/exception.rb', line 26 def framework_backtrace clean_backtrace.select {|line| line =~ FrameworkRegexp} end |