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

Instance Method Details

#application_backtraceObject


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


223
224
225
# File 'lib/active_support/dependencies.rb', line 223

def blame_file!(file)
  (@blamed_files ||= []).unshift file
end

#blamed_filesObject


227
228
229
# File 'lib/active_support/dependencies.rb', line 227

def blamed_files
  @blamed_files ||= []
end

#clean_backtraceObject


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


236
237
238
239
# File 'lib/active_support/dependencies.rb', line 236

def copy_blame!(exc)
  @blamed_files = exc.blamed_files.clone
  self
end

#describe_blameObject


231
232
233
234
# File 'lib/active_support/dependencies.rb', line 231

def describe_blame
  return nil if blamed_files.empty?
  "This error occured while loading the following files:\n   #{blamed_files.join "\n   "}"
end

#framework_backtraceObject


26
27
28
# File 'lib/active_support/core_ext/exception.rb', line 26

def framework_backtrace
  clean_backtrace.select {|line| line =~ FrameworkRegexp}
end