Skip to content

Commit 147c42a

Browse files
committed
Fix formatting in Exception#full_message when RuntimeError is not handled and :highlight option is specified
1 parent 451a07d commit 147c42a

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Compatibility:
3737
* Fix `StringIO#initialize` and preserve initial string's encoding when mode is `w` so the initial string is truncated (#3599, @andrykonchin).
3838
* Fix `IO#{autoclose=,autoclose?}` and raise `IOError` when io is closed (@andrykonchin).
3939
* Fix `Thread#{thread_variable_get,thread_variable_set,thread_variable?,key?,[],[]=,fetch}` and convert a non-String/Symbol thread-local variable name to String using `#to_str` (@andrykonchin).
40+
* Fix formatting in `Exception#full_message` when `RuntimeError` is not handled and `highlight` option is specified (@andrykonchin).
4041

4142
Performance:
4243

spec/ruby/core/exception/full_message_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@
7979
err.full_message(highlight: true).should !~ /unhandled exception/
8080
err.full_message(highlight: false).should !~ /unhandled exception/
8181
end
82+
83+
it "adds escape sequences to highlight some strings if the message is not specified and :highlight option is specified" do
84+
e = RuntimeError.new("")
85+
86+
full_message = e.full_message(highlight: true, order: :top).lines
87+
full_message[0].should.end_with? "\e[1;4munhandled exception\e[m\n"
88+
89+
full_message = e.full_message(highlight: true, order: :bottom).lines
90+
full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n"
91+
full_message[-1].should.end_with? "\e[1;4munhandled exception\e[m\n"
92+
93+
full_message = e.full_message(highlight: false, order: :top).lines
94+
full_message[0].should.end_with? "unhandled exception\n"
95+
96+
full_message = e.full_message(highlight: false, order: :bottom).lines
97+
full_message[0].should == "Traceback (most recent call last):\n"
98+
full_message[-1].should.end_with? "unhandled exception\n"
99+
end
82100
end
83101

84102
describe "generic Error" do

spec/tags/core/exception/detailed_message_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def self.detailed_message(exception, highlight)
116116

117117
if message.empty?
118118
message = Primitive.equal?(exception_class, RuntimeError) ? 'unhandled exception' : class_name
119-
message = "\n\e[1m#{message}\e[m" if highlight
119+
message = "\e[1;4m#{message}\e[m" if highlight
120120
return message
121121
end
122122

0 commit comments

Comments
 (0)