Skip to content

Commit 204f631

Browse files
mameschneems
authored andcommitted
[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. 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. ruby/rubygems@8f104228d3
1 parent 61d5a99 commit 204f631

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/rubygems/command_manager.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ def command_names
148148
def run(args, build_args=nil)
149149
process_args(args, build_args)
150150
rescue StandardError, Timeout::Error => ex
151-
alert_error clean_text("While executing gem ... (#{ex.class})\n #{ex}")
151+
if ex.respond_to?(:detailed_message)
152+
msg = ex.detailed_message(highlight: false).sub(/\A(.*?)(?: \(.+?\))/) { $1 }
153+
else
154+
msg = ex.message
155+
end
156+
alert_error clean_text("While executing gem ... (#{ex.class})\n #{msg}")
152157
ui.backtrace ex
153158

154159
terminate_interaction(1)

test/rubygems/test_gem_command_manager.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ def test_find_command_unknown_suggestions
8080
message << "\nDid you mean? \"push\""
8181
end
8282

83-
assert_equal message, e.message
83+
if e.respond_to?(:detailed_message)
84+
actual_message = e.detailed_message(highlight: false).sub(/\A(.*?)(?: \(.+?\))/) { $1 }
85+
else
86+
actual_message = e.message
87+
end
88+
89+
assert_equal message, actual_message
8490
end
8591

8692
def test_run_interrupt

0 commit comments

Comments
 (0)