[ruby/irb] Filter backtrace before format in handle_exception
(https://github.com/ruby/irb/pull/916) handle_exception now applies the filter_backtrace to exception backtraces prior to formatting the lines with Exception#full_message This fixes a bug in upstream projects, notably Rails, where the backtrace filtering logic expects the lines to be formatted as Exception#backtrace. https://github.com/ruby/irb/commit/805ee008f9 Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
This commit is contained in:
parent
dbe8886f4d
commit
f87e60f1f4
@ -1222,6 +1222,13 @@ module IRB
|
|||||||
irb_bug = true
|
irb_bug = true
|
||||||
else
|
else
|
||||||
irb_bug = false
|
irb_bug = false
|
||||||
|
# This is mostly to make IRB work nicely with Rails console's backtrace filtering, which patches WorkSpace#filter_backtrace
|
||||||
|
# In such use case, we want to filter the exception's backtrace before its displayed through Exception#full_message
|
||||||
|
# And we clone the exception object in order to avoid mutating the original exception
|
||||||
|
# TODO: introduce better API to expose exception backtrace externally
|
||||||
|
backtrace = exc.backtrace.map { |l| @context.workspace.filter_backtrace(l) }.compact
|
||||||
|
exc = exc.clone
|
||||||
|
exc.set_backtrace(backtrace)
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION < '3.0.0'
|
if RUBY_VERSION < '3.0.0'
|
||||||
@ -1246,7 +1253,6 @@ module IRB
|
|||||||
lines = m.split("\n").reverse
|
lines = m.split("\n").reverse
|
||||||
end
|
end
|
||||||
unless irb_bug
|
unless irb_bug
|
||||||
lines = lines.map { |l| @context.workspace.filter_backtrace(l) }.compact
|
|
||||||
if lines.size > @context.back_trace_limit
|
if lines.size > @context.back_trace_limit
|
||||||
omit = lines.size - @context.back_trace_limit
|
omit = lines.size - @context.back_trace_limit
|
||||||
lines = lines[0..(@context.back_trace_limit - 1)]
|
lines = lines[0..(@context.back_trace_limit - 1)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user