WriteError overwrites InvocationInfo
See original GitHub issueWe have custom cmdlets that call other cmdlets and scripts. Sometimes these other cmdlets return errors in the Error stream(PowerShell.Streams.Error
). Since the PowerShell
class does not write the errors to the host/console, we write the ErrorRecords located in the stream out to WriteError. When doing so, the console shows our cmdlet name as the source instead of the original that is already in the InvocationInfo property in the ErrorRecord.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15
Top Results From Across the Web
Improve output format of caught exception, using Write-Error
1 Answer. As you have noticed, when you call Write-Error in a catch block, the error message only shows the origin of the...
Read more >Windows PowerShell Error Records
WriteError or System.Management.Automation.Cmdlet.Throwterminatingerror* methods are called. To add a replacement message, set the System.
Read more >Everything you wanted to know about exceptions
By default, a non-terminating error is generated by Write-Error and ... Here is the InvocationInfo from the sample exception that I created.
Read more >about Preference Variables - PowerShell
The $ErrorActionPreference variable takes one of the ActionPreference enumeration values: SilentlyContinue, Stop, Continue, Inquire, Ignore, ...
Read more >Private/UserInteraction/WriteError.ps1 1.0.1
Exception | Get-Member | Select-Object -ExpandProperty TypeName -Unique)]" if ($incomingError.InvocationInfo.Line) { Write-Host "Command : [$($RaisedError.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe this is by design?
WriteError()
andThrowTerminatingError()
are intended to show their parent command as the source of the error.You will have to give me some time to put together a sample project.