- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@mklement0 Does the PR fix your issue? |
LGTM. Thanks for tackling this,@MatejKafka. |
MatejKafka commentedFeb 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.ps1Show resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
MatejKafka commentedFeb 7, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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). |
Uh oh!
There was an error while loading.Please reload this page.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
9071eac
intoPowerShell:masterUh oh!
There was an error while loading.Please reload this page.
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 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:
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
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).