-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add null check for args in CommandLineParser #13451
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
Conversation
|
While we are here maybe add a comment like "The 'args' can not be null and can not contain null elements." in XML summary for all public methods where it is used? |
| { | ||
| if (args[i] is null) | ||
| { | ||
| throw new ArgumentNullException("The 'args' array contains a null element."); |
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.
The message should be put in .resx file. Make the message to "The specified arguments should not contain null elements.". Also, please pass in the parameter name to ArgumentNullException.
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.
nameof(args)
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.
No exceptions in the file use Resx file.
Please confirm using Resx file in the case.
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 think you need to differentiate an exception thrown due to user action from an exception that's thrown due to internal error only.
The InvalidOperationException thrown when _dirty == true can happen only when there is an internal error -- the parser gets reused somehow. It shouldn't happen and is not user facing.
The ArgumentNullException thrown here only because a user action -- the user pass in invalid args. It's user facing. For user-facing exceptions, the message should be localized eventually.
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 see your point. The issue could be raised (1) only in host application, (2) only if the host application developer constructs args with null element. So it is not "end user action" but a bug in the host application that is "internal error" case too. It looks the same as if we passed a bug with _dirty and an user catches this edge case with non-localized message. Thoughts?
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.
Anyone using a PowerShell public API is an end user. An internal error is an error that cannot be triggered by an end user. In this case, an end user cannot cause the argument parser to be reused.
I hope this makes it more clear to you.
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 clarify!
Done.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@daxian-dbw please update your review |
|
Review updated: #13451 (comment) |
src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx
Outdated
Show resolved
Hide resolved
…meterParserStrings.resx Co-authored-by: Robert Holt <rjmholt@gmail.com>
|
🎉 Handy links: |
PR Summary
Throw if
argsarray contains a null.PR Context
#13429 (comment)
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.