question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WriteError overwrites InvocationInfo

See original GitHub issue

We 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:open
  • Created 4 years ago
  • Comments:15

github_iconTop GitHub Comments

2reactions
vexx32commented, Oct 8, 2019

I believe this is by design? WriteError() and ThrowTerminatingError() are intended to show their parent command as the source of the error.

1reaction
johnwccommented, Oct 9, 2019

You will have to give me some time to put together a sample project.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found