Skip to content

Commit

Permalink
[rubygems/rubygems] Support the change of did_you_mean about Exceptio…
Browse files Browse the repository at this point in the history
…n#detailed_message

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

ruby/did_you_mean#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.

rubygems/rubygems@8f104228d3
  • Loading branch information
mame authored and matzbot committed May 23, 2022
1 parent 4cf155e commit 663915d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rubygems/command_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ def command_names
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)
Expand Down
8 changes: 7 additions & 1 deletion test/rubygems/test_gem_command_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def test_find_command_unknown_suggestions
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
Expand Down

0 comments on commit 663915d

Please sign in to comment.