-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add more specific sub command error handling #6038
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
Add more specific sub command error handling #6038
Conversation
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 working on this @TylerSustare 👍
Can you add a unit test for this so that we can be sure that it won't be altered accidentally in the future? Thanks!
describe('#getCommand()', () => { | ||
beforeEach(() => { | ||
pluginManager.addPlugin(SynchronousPluginMock); | ||
pluginManager.serverless.cli.loadedCommands = { |
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.
@pmuens Absolutely! Good call on adding a test for it.
When adding the loadedCommands
I would normally put this JS object in a fixtures
file but it didn't look like this project really uses fixtures. So I put it in line with the test. Let me know if there is a preferred way to do this.
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.
Sounds good. Yes, using this inline should be ok 👍
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.
Just tested it and it works fine! Thanks for working on this @TylerSustare 👍
LGMT
describe('#getCommand()', () => { | ||
beforeEach(() => { | ||
pluginManager.addPlugin(SynchronousPluginMock); | ||
pluginManager.serverless.cli.loadedCommands = { |
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.
Sounds good. Yes, using this inline should be ok 👍
What did you implement:
Closes #6035
How did you implement it:
Before sending the user to
getCommandSuggestion
, if the previous commands are valid, return a message telling the user how better to self-correct. Admittedly this message is only to tell the user how to run a command that will give him/her a better error message. Most error handling is handled well in the serverless framework. However, for these niche cases, I feel this is a slight improvement.How can we verify it:
This is only handled in error cases where the framework is basically saying "We don't know what you want". I couldn't find any tests for this case to modify.

Current handling:
With this change:

This change does not conflict with any other
validation
methods. For examplevalidateOptions()
still runs as anticipated since this error case is only with commands or aliases.Todos:
Is this ready for review?: YES
Is it a breaking change?: NO