Skip to content

Conversation

@mame
Copy link
Member

@mame mame commented May 23, 2022

This changeset lets DidYouMean::Correctable to use #detailed_message,
which is Ruby 3.2's more dedicated way to show additional error
information like did_you_mean and error_highlight.

There are some problems with the approach of overriding #message.
One is that the approach breaks a test that checks a return value
of #message. I actually faced this kind of issues in real-world
applications when I was implementing error_highlight with the same
approach as did_you_mean.
See minitest/minitest#880 for example.

For this reason, error_highlight enhances only NameError.
The support of other error types such as TypeError and ArgumentError is
currently disabled because it breaks more tests:
https://github.com/ruby/error_highlight/blob/f88b6fab2ff34559a0f08d019d574dbb52426a20/lib/error_highlight/core_ext.rb#L49-L52

I believe #detailed_message will solve the issue.
I want did_you_mean and error_highlight to use the new API instead of
clobbering #message method.
See https://bugs.ruby-lang.org/issues/18564 for detail.

This changeset lets DidYouMean::Correctable to use #detailed_message,
which is Ruby 3.2's more dedicated way to show additional error
information like did_you_mean and error_highlight.

There are some problems with the approach of overriding #message.
One is that the approach breaks a test that checks a return value
of #message. I actually faced this kind of issues in real-world
applications when I was implementing error_highlight with the same
approach as did_you_mean.
See minitest/minitest#880 for example.

For this reason, error_highlight enhances only NameError.
The support of other error types such as TypeError and ArgumentError is
currently disabled because it breaks more tests:
https://github.com/ruby/error_highlight/blob/f88b6fab2ff34559a0f08d019d574dbb52426a20/lib/error_highlight/core_ext.rb#L49-L52

I believe #detailed_message will solve the issue.
I want did_you_mean and error_highlight to use the new API instead of
clobbering #message method.
See https://bugs.ruby-lang.org/issues/18564 for detail.
mame added a commit to mame/rubygems that referenced this pull request May 23, 2022
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.
matzbot pushed a commit to ruby/ruby that referenced this pull request May 23, 2022
…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.

ruby/rubygems@8f104228d3
@yuki24 yuki24 merged commit 0b1942b into ruby:master May 24, 2022
matzbot pushed a commit to ruby/ruby that referenced this pull request Jun 7, 2022
schneems pushed a commit to schneems/ruby that referenced this pull request Jul 26, 2022
…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.

ruby/rubygems@8f104228d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants