GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fetch resource string correctly by daxian-dbw · Pull Request #5114 · PowerShell/PowerShell

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Oct 14, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I found Add-Member throws error with an empty message. This PR fixes it.

Before fix

PS:2> Add-Member -InputObject $object "ABC" "Value1"
[C:\arena\pscore]
PS:3> Add-Member -InputObject $object "ABC" "Value1"
Add-Member :
At line:1 char:1
+ Add-Member -InputObject $object "ABC" "Value1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (1 2:PSObject) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand

After fix

PS:8> Add-Member -InputObject $object "ABC" "Value1"
Add-Member : Cannot add a member with the name "ABC" because a member with that name already exists. To overwrite the
member anyway, add the Force parameter to your command.
At line:1 char:1
+ Add-Member -InputObject $object "ABC" "Value1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (1 2:PSObject) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand

Also updated a resource string use in ConvertTo-Json to directly use the C# property.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw
Fetch resource string correctly
20eda51
@daxian-dbw Dongbo Wang (daxian-dbw) assigned Aditya Patwardhan (adityapatwardhan) Oct 14, 2017
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a review from Aditya Patwardhan (adityapatwardhan) October 14, 2017 04:42
@daxian-dbw
Dongbo Wang (daxian-dbw) requested review from James Truher (JamesWTruher), Paul Higinbotham (PaulHigin) and Dan Travison (dantraMSFT) as code owners October 14, 2017 04:42
iSazonov
Ilya (iSazonov) reviewed Oct 15, 2017
View reviewed changes
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
"WebCmdletStrings", "JsonStringInBadFormat");
ErrorRecord errorRecord = new ErrorRecord(
new InvalidOperationException(details.Message),
new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat),

@iSazonov Ilya (iSazonov) Oct 15, 2017

Copy link
Copy Markdown
Collaborator

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 15, 2017

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 16, 2017

Copy link
Copy Markdown
Collaborator

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 16, 2017

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@PaulHigin Paul Higinbotham (PaulHigin) Oct 16, 2017

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 16, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
PaulHigin
Paul Higinbotham (PaulHigin) approved these changes Oct 16, 2017
View reviewed changes

@PaulHigin Paul Higinbotham (PaulHigin) left a comment

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
"WebCmdletStrings", "JsonStringInBadFormat");
ErrorRecord errorRecord = new ErrorRecord(
new InvalidOperationException(details.Message),
new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat),

@PaulHigin Paul Higinbotham (PaulHigin) Oct 16, 2017

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iSazonov
Ilya (iSazonov) approved these changes Oct 17, 2017
View reviewed changes
adityapatwardhan
Aditya Patwardhan (adityapatwardhan) approved these changes Oct 18, 2017
View reviewed changes
@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 2ceec72 into PowerShell:master Oct 18, 2017
@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the errorstring branch October 18, 2017 19:27
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@daxian-dbw @adityapatwardhan
Fetch resource string correctly (PowerShell#5114)
1fe3261
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) adityapatwardhan approved these changes
@iSazonov Ilya (iSazonov) iSazonov approved these changes
@dantraMSFT Dan Travison (dantraMSFT) Awaiting requested review from dantraMSFT
@JamesWTruher James Truher (JamesWTruher) Awaiting requested review from JamesWTruher
+1 more reviewer
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adityapatwardhan Aditya Patwardhan (adityapatwardhan)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@daxian-dbw @adityapatwardhan @PaulHigin @iSazonov
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.