Skip to content

Commit 23dd067

Browse files
committed
[GR-34365] Exception#full_message should default the order to :top since Ruby 3
PullRequest: truffleruby/3294
2 parents 4e6de55 + 1b64490 commit 23dd067

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Bug fixes:
1212
Compatibility:
1313

1414
* Fix `Marshal.dump` to raise an error when an object has singleton methods (@bjfish).
15+
* `Exception#full_message` now defaults the order to `:top` like CRuby 3+ (@eregon).
1516

1617
Performance:
1718

spec/mspec/lib/mspec/matchers/output.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def failure_message
4242
expected_out = "\n"
4343
actual_out = "\n"
4444
unless @out.nil?
45-
expected_out += " $stdout: #{@out.inspect}\n"
46-
actual_out += " $stdout: #{@stdout.inspect}\n"
45+
expected_out += " $stdout: #{MSpec.format(@out)}\n"
46+
actual_out += " $stdout: #{MSpec.format(@stdout.to_s)}\n"
4747
end
4848
unless @err.nil?
49-
expected_out += " $stderr: #{@err.inspect}\n"
50-
actual_out += " $stderr: #{@stderr.inspect}\n"
49+
expected_out += " $stderr: #{MSpec.format(@err)}\n"
50+
actual_out += " $stderr: #{MSpec.format(@stderr.to_s)}\n"
5151
end
5252
["Expected:#{expected_out}", " got:#{actual_out}"]
5353
end

spec/ruby/core/thread/report_on_exception_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@
6161
}.should raise_error(RuntimeError, "Thread#report_on_exception specs")
6262
end
6363

64+
ruby_version_is "3.0" do
65+
it "prints a backtrace on $stderr in the regular backtrace order" do
66+
line_raise = __LINE__ + 2
67+
def foo
68+
raise RuntimeError, "Thread#report_on_exception specs backtrace order"
69+
end
70+
71+
line_call_foo = __LINE__ + 5
72+
go = false
73+
t = Thread.new {
74+
Thread.current.report_on_exception = true
75+
Thread.pass until go
76+
foo
77+
}
78+
79+
-> {
80+
go = true
81+
Thread.pass while t.alive?
82+
}.should output("", <<ERR)
83+
#{t.inspect} terminated with exception (report_on_exception is true):
84+
#{__FILE__}:#{line_raise}:in `foo': Thread#report_on_exception specs backtrace order (RuntimeError)
85+
\tfrom #{__FILE__}:#{line_call_foo}:in `block (5 levels) in <top (required)>'
86+
ERR
87+
88+
-> {
89+
t.join
90+
}.should raise_error(RuntimeError, "Thread#report_on_exception specs backtrace order")
91+
end
92+
end
93+
6494
it "prints the backtrace even if the thread was killed just after Thread#raise" do
6595
t = nil
6696
ready = false

src/main/ruby/truffleruby/core/exception.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def inspect
8787
end
8888
end
8989

90-
def full_message(highlight: nil, order: undefined)
90+
def full_message(highlight: nil, order: :top)
9191
Truffle::ExceptionOperations.full_message(self, highlight, order)
9292
end
9393

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,9 @@ def self.full_message(exception, highlight, order)
127127
raise ArgumentError, "expected true of false as highlight: #{highlight}" unless highlight.equal?(true) || highlight.equal?(false)
128128
!highlight.equal?(false)
129129
end
130-
reverse = if Primitive.undefined?(order)
131-
Exception.to_tty?
132-
else
133-
raise ArgumentError, "expected :top or :bottom as order: #{order}" unless order.equal?(:top) || order.equal?(:bottom)
134-
!order.equal?(:top)
135-
end
130+
131+
raise ArgumentError, "expected :top or :bottom as order: #{order}" unless order.equal?(:top) || order.equal?(:bottom)
132+
reverse = !order.equal?(:top)
136133

137134
result = ''.b
138135
bt = exception.backtrace || caller(2)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def self.detect_outermost_recursion(obj, &block)
161161
end
162162

163163
def self.report_exception(thread, exception)
164-
message = "#{thread.inspect} terminated with exception:\n#{exception.full_message}"
164+
message = "#{thread.inspect} terminated with exception (report_on_exception is true):\n#{exception.full_message}"
165165
$stderr.write message
166166
end
167167

0 commit comments

Comments
 (0)