Skip to content

Commit 10e31e9

Browse files
committed
Fix Exception#full_message when given cause with empty backtrace
The issue leads to the following error: ``` NameError: undefined local variable or method `exception' for module Truffle::ExceptionOperations <internal:core> core/truffle/exception_operations.rb:319:in `append_causes' <internal:core> core/truffle/exception_operations.rb:270:in `full_message' <internal:core> core/exception.rb:81:in `full_message' ```
1 parent e15c7e8 commit 10e31e9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spec/ruby/core/exception/full_message_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,16 @@ class << e
211211
e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
212212
e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
213213
end
214+
215+
it "allows cause with empty backtrace" do
216+
begin
217+
raise RuntimeError.new("Some runtime error"), cause: RuntimeError.new("Some other runtime error")
218+
rescue => e
219+
end
220+
221+
full_message = e.full_message
222+
full_message.should include "RuntimeError"
223+
full_message.should include "Some runtime error"
224+
full_message.should include "Some other runtime error"
225+
end
214226
end

src/main/ruby/truffleruby/core/truffle/exception_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ def self.append_causes(str, err, causes, reverse, highlight, options)
297297
append_causes(str, cause, causes, reverse, highlight, options)
298298
backtrace_message = backtrace_message(highlight, reverse, cause.backtrace, cause, options)
299299
if backtrace_message.empty?
300-
str << detailed_message_or_fallback(exception, options)
300+
str << detailed_message_or_fallback(cause, options)
301301
else
302302
str << backtrace_message
303303
end
304304
else
305305
backtrace_message = backtrace_message(highlight, reverse, cause.backtrace, cause, options)
306306
if backtrace_message.empty?
307-
str << detailed_message_or_fallback(exception, options)
307+
str << detailed_message_or_fallback(cause, options)
308308
else
309309
str << backtrace_message
310310
end

0 commit comments

Comments
 (0)