-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fetch resource string correctly #5114
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
| "WebCmdletStrings", "JsonStringInBadFormat"); | ||
| ErrorRecord errorRecord = new ErrorRecord( | ||
| new InvalidOperationException(details.Message), | ||
| new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat), |
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.
Is the change for the PR? I don't see a description and a test.
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.
If the resource file name and the resource string id is known/fixed, there is no point to use ResourceManager to retrieve the error message (which is what ErrorDetails does). Instead, we can just use the generated C# property.
The existence of the resource string is guaranteed by the build, so I didn't add a test for it.
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 meant that the PR description mention only Add-Member cmdlet but not ConvertTo-Json.
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.
Updated the description to include the ConvertTo-Json change.
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 error string for this resource (WebCmdletStrings.JsonStringInBadFormat) doesn't seem right:
"The converted JSON string is in bad format."
I think this would be a better error message:
"The JSON string could not be converted because the format is incorrect."
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.
This code is from ConvertTo-Json cmdlet, which takes arbitrary objects and converts them to JSON string. The error message is used when it detects the JSON string we converted to is in bad format.
PaulHigin
left a comment
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.
Please also update the WebCmdletStrings.JsonStringInBadFormat error string.
| "WebCmdletStrings", "JsonStringInBadFormat"); | ||
| ErrorRecord errorRecord = new ErrorRecord( | ||
| new InvalidOperationException(details.Message), | ||
| new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat), |
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 error string for this resource (WebCmdletStrings.JsonStringInBadFormat) doesn't seem right:
"The converted JSON string is in bad format."
I think this would be a better error message:
"The JSON string could not be converted because the format is incorrect."
I found
Add-Memberthrows error with an empty message. This PR fixes it.Before fix
After fix
Also updated a resource string use in
ConvertTo-Jsonto directly use the C# property.