Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private void UpdateTypeNames()
private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args)
{
ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly,
"AddMember", resourceId, args);
"Microsoft.PowerShell.Commands.Utility.resources.AddMember", resourceId, args);
ErrorRecord errorRecord = new ErrorRecord(
new InvalidOperationException(details.Message),
errorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,8 @@ private void AddSpaces(int numberOfSpacesToReturn, StringBuilder result)

private ErrorRecord NewError()
{
ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly,
"WebCmdletStrings", "JsonStringInBadFormat");
ErrorRecord errorRecord = new ErrorRecord(
new InvalidOperationException(details.Message),
new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat),
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Contributor

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."

Copy link
Member Author

@daxian-dbw daxian-dbw Oct 16, 2017

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.

"JsonStringInBadFormat",
ErrorCategory.InvalidOperation,
InputObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@
$results = add-member -InputObject a 16 sp {1+1} -passthru
$results.sp | Should Be 2
}

It "Verify Add-Member error message is not empty" {
$object = @(1,2)
Add-Member -InputObject $object "ABC" "Value1"
Add-Member -InputObject $object "ABC" "Value2" -ErrorVariable errorVar -ErrorAction SilentlyContinue
$errorVar.Exception | Should BeOfType "System.InvalidOperationException"
$errorVar.Exception.Message | Should Not BeNullOrEmpty
}
}

Describe "Add-Member" -Tags "CI" {
Expand Down