[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 коммит произвёл git
Родитель 4cf155e007
Коммит 663915ddf4
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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