1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Support the change of did_you_mean about Exception#detailed_message

I am asking did_you_mean to use Exception#detailed_message to add
"Did you mean?" suggestion instead of overriding #message method.

https://github.com/ruby/did_you_mean/pull/177

Unfortunately, the change will affect Gem::UnknownCommandError, which
excepts did_you_mean to override #message method.

This PR absorbs the change of did_you_mean.
Gem::CommandManager now calls #detailed_message method to get a message
string with "Did you mean?" suggestion from an exception.

https://github.com/rubygems/rubygems/commit/8f104228d3
This commit is contained in:
Yusuke Endoh 2022-05-23 18:45:39 +09:00 committed by git
parent 4cf155e007
commit 663915ddf4
2 changed files with 13 additions and 2 deletions

View file

@ -148,7 +148,12 @@ class Gem::CommandManager
def run(args, build_args=nil)
process_args(args, build_args)
rescue StandardError, Timeout::Error => ex
alert_error clean_text("While executing gem ... (#{ex.class})\n #{ex}")
if ex.respond_to?(:detailed_message)
msg = ex.detailed_message(highlight: false).sub(/\A(.*?)(?: \(.+?\))/) { $1 }
else
msg = ex.message
end
alert_error clean_text("While executing gem ... (#{ex.class})\n #{msg}")
ui.backtrace ex
terminate_interaction(1)

View file

@ -80,7 +80,13 @@ class TestGemCommandManager < Gem::TestCase
message << "\nDid you mean? \"push\""
end
assert_equal message, e.message
if e.respond_to?(:detailed_message)
actual_message = e.detailed_message(highlight: false).sub(/\A(.*?)(?: \(.+?\))/) { $1 }
else
actual_message = e.message
end
assert_equal message, actual_message
end
def test_run_interrupt