Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / activesupport / lib / active_support / core_ext / exception.rb
1 module ActiveSupport
2 if RUBY_VERSION >= '1.9'
3 FrozenObjectError = RuntimeError
4 else
5 FrozenObjectError = TypeError
6 end
7 end
8
9 # TODO: Turn all this into using the BacktraceCleaner.
10 class Exception # :nodoc:
11 def clean_message
12 Pathname.clean_within message
13 end
14
15 TraceSubstitutions = []
16 FrameworkStart = /action_controller\/dispatcher\.rb/.freeze
17 FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/.freeze
18
19 def clean_backtrace
20 backtrace.collect do |line|
21 Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)|
22 result.gsub regexp, sub
23 end)
24 end
25 end
26
27 def application_backtrace
28 before_framework_frame = nil
29 before_application_frame = true
30
31 trace = clean_backtrace.reject do |line|
32 before_framework_frame ||= (line =~ FrameworkStart)
33 non_app_frame = (line =~ FrameworkRegexp)
34 before_application_frame = false unless non_app_frame
35 before_framework_frame || (non_app_frame && !before_application_frame)
36 end
37
38 # If we didn't find any application frames, return an empty app trace.
39 before_application_frame ? [] : trace
40 end
41
42 def framework_backtrace
43 clean_backtrace.grep FrameworkRegexp
44 end
45 end