New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnrecognizedCommandError can be corrected and retried #51502
base: main
Are you sure you want to change the base?
Conversation
6ee9342
to
81a2461
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like this. Left a comment about changelog wording.
railties/CHANGELOG.md
Outdated
* When encountering an Unrecognized Command Error, the developer will be given the option to | ||
run of the suggested corrections instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the wording a little confusing. How about:
* When encountering an Unrecognized Command Error, the developer will be given the option to | |
run of the suggested corrections instead. | |
* When encountering an Unrecognized Command Error while running `rails` commands, the developer will be | |
given the option to run the suggested corrections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I sometimes find writing these change logs harder than writing the code 😅
When encountering a UnrecognizedCommandError, the developer will be given the option to run of the suggested corrections instead. Co-authored-by: Gannon McGibbon <gannon.mcgibbon@gmail.com>
81a2461
to
2b16ae8
Compare
Nice change! ➜ myapp git:(main) bin/rails active_text:install
Unrecognized command "active_text:install"
Did you mean?
1. action_text:install
2. active_storage:install |
@p8 Glad you like it :D Yes, you could get more than one correction. In which case you would get prompted for the first, if you say no, then you'll get prompted for the next one, and so on. The output is like: In reality I wonder how common that is though - this example is somewhat contrived as a real user probably would have said "yes" to I do like the idea of seeing all the options and selecting them by number. Maybe I can go back and look at how to accomplish that with thor. |
I'm not a fan of turning a non-interactive command into an interactive one on the failure path. It interferes with usual CLI error handling, and risks hanging the process -- the tty check is useful, but I'm pretty sure it's not perfect. Suggesting action text vs active storage seems like an illustration of when it's not helpful, too: if our suggestion isn't pretty close to what they asked for, then the problem likely lies elsewhere (they spelled it correctly, but need to add a gem first). Potentially making multiple implausible guesses, one at a time, when they can immediately see what they actually need to do next, feels hostile. |
We spent awhile trying to circumvent the
True. Maybe we could limit the suggestion to one correction, at least limit it to 3 at most. |
Motivation / Background
This is a follow up to #50941. "Did you mean?" style errors were introduced in 2530160 for unrecognized commands. With this change, we give the user the option to retry with the corrected command name - instead of needing to retype and rerun the command.
Detail
We iterate through all the possible commands returned by
DidYouMean::SpellChecker
and give the user the option to rerun the suggested correction.Additional information
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]