Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stringify ErrorRecord with empty exception message to empty string#24949

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iSazonov merged 3 commits intoPowerShell:masterfromMatejKafka:error-record
Feb 10, 2025

Conversation

MatejKafka
Copy link
Contributor

PR Summary

Fixes#23950.

PR Context

When a native process writes a line to stderr, PowerShell wraps it in anErrorRecord. Users often want to merge the stdout and stderr streams, at which point they need to convert theErrorRecord from stderr back to a string. However, before this PR, anErrorRecord with an empty exception message string stringifies to the name of the exception (System.Management.Automation.RemoteException for this specific scenario), which requires the user to use various workarounds (e.g. grabbing.Exception.Message manually) to get the original string.

Reproduction:

$(try {throw""}catch {$_})|% {"$_"}# System.Management.Automation.RuntimeException

This PR makes.ToString() behave consistently even for empty exception messages, so just running.ToString() on items from stderr should be enough to get back the original strings. While this is technically a breaking change, I'm pretty sure it falls into bucket 3 (unlikely gray area).

PR Checklist

@iSazonov
Copy link
Collaborator

@mklement0 Does the PR fix your issue?

@mklement0
Copy link
Contributor

LGTM. Thanks for tackling this,@MatejKafka.

iSazonov reacted with thumbs up emoji

@iSazonoviSazonov added the CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log labelFeb 5, 2025
@MatejKafka
Copy link
ContributorAuthor

MatejKafka commentedFeb 6, 2025
edited
Loading

Updated a Pester test that was using-IsNullOrEmpty on anErrorRecord (which implicitly converts to string before doing the comparison).

@MatejKafka
Copy link
ContributorAuthor

@iSazonov Would you please re-approve the CI?

@iSazonov

This comment was marked as outdated.

@azure-pipelinesAzure Pipelines

This comment was marked as outdated.

@MatejKafka
Copy link
ContributorAuthor

MatejKafka commentedFeb 7, 2025
edited
Loading

@iSazonov I don't think the failed tests are related to this PR – they're in PSResourceGet, and the code where the error seems to come from does not work with otherErrorRecords at all. I'd suspect that something is broken with the test repository setup.

@iSazonov
Copy link
Collaborator

/azp run

@azure-pipelinesAzure Pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@iSazonoviSazonov reopened thisFeb 8, 2025
@iSazonov
Copy link
Collaborator

/azp run

@azure-pipelinesAzure Pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@iSazonoviSazonov changed the titleStringify ErrorRecord with empty exception message to empty string (#23950)Stringify ErrorRecord with empty exception message to empty stringFeb 10, 2025
@iSazonoviSazonov merged commit9071eac intoPowerShell:masterFeb 10, 2025
38 of 41 checks passed
@iSazonoviSazonov self-assigned thisFeb 10, 2025
@MatejKafkaMatejKafka deleted the error-record branchJune 29, 2025 12:44
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@iSazonoviSazonoviSazonov approved these changes

Assignees

@iSazonoviSazonov

Labels
CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

EmptyErrorRecord-wrapped stderr lines stringify as the exception type name rather than as the empty string
3 participants
@MatejKafka@iSazonov@mklement0

[8]ページ先頭

©2009-2025 Movatter.jp