Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only append highlight to Exception#to_s, not #message #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/error_highlight/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ module CoreExt
SKIP_TO_S_FOR_SUPER_LOOKUP = true
private_constant :SKIP_TO_S_FOR_SUPER_LOOKUP

def self.apply(error_class)
error_class.alias_method(:message, :to_s)
error_class.prepend(self)
end

def to_s
msg = super.dup

Expand Down Expand Up @@ -41,10 +46,10 @@ def to_s
end
end

NameError.prepend(CoreExt)
CoreExt.apply(NameError)

# The extension for TypeError/ArgumentError is temporarily disabled due to many test failures

#TypeError.prepend(CoreExt)
#ArgumentError.prepend(CoreExt)
# CoreExt.apply(TypeError)
# CoreExt.apply(ArgumentError)
end
9 changes: 8 additions & 1 deletion test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def teardown

def assert_error_message(klass, expected_msg, &blk)
err = assert_raise(klass, &blk)
assert_equal(expected_msg.chomp, err.message)
assert_equal(expected_msg.chomp, err.to_s)
end

def test_CALL_noarg_1
Expand Down Expand Up @@ -1018,6 +1018,13 @@ def test_hard_tabs
end
end

def test_message
error = assert_raises NoMethodError do
nil.foo
end
assert_equal "undefined method `foo' for nil:NilClass", error.message
end

def test_no_final_newline
Tempfile.create(["error_highlight_test", ".rb"], binmode: true) do |tmp|
tmp << "1.time {}"
Expand Down