-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@mklement0 Does the PR fix your issue? |
|
LGTM. Thanks for tackling this, @MatejKafka. |
1e3171f to
3ddbdba
Compare
|
Updated a Pester test that was using |
|
@iSazonov Would you please re-approve the CI? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1
Show resolved
Hide resolved
|
@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 other |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |


PR Summary
Fixes #23950.
PR Context
When a native process writes a line to stderr, PowerShell wraps it in an
ErrorRecord. Users often want to merge the stdout and stderr streams, at which point they need to convert theErrorRecordfrom stderr back to a string. However, before this PR, anErrorRecordwith an empty exception message string stringifies to the name of the exception (System.Management.Automation.RemoteExceptionfor this specific scenario), which requires the user to use various workarounds (e.g. grabbing.Exception.Messagemanually) to get the original string.Reproduction:
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
.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.- [ ] Issue filed:
(which runs in a different PS Host).