Product: PowerShell Universal
Version: 4.4.1
I cannot seem to find the doc on this. How would i enable the stacktrace and line number of the error when i am looking at my logs?
Product: PowerShell Universal
Version: 4.4.1
I cannot seem to find the doc on this. How would i enable the stacktrace and line number of the error when i am looking at my logs?
Stack traces and line numbers only show up if the exception is passed to the logging functions. Are you looking for line numbers\stack trace when using Write-PSULog?
so, lets say there is an error, it blows a message out to the logs, sometimes it is hard to find what blew the error. Then i end up writing every other line with a write-host.
Write-host “Past this line”
#bla
Write-host “start x line”
etc
In APIs, scripts, apps? PS errors (currently) are handled differently than .NET ones. We could improve this but maybe more specifics would help.
all of the above.
lets say i run a normal script, it blows an error, and it gives me a line number in the error. i am looking for something like this that i can turn on. for some reason i thought in the past it did do that, but then got cleaned up or something.
I see what you’re talking about. I did some tests in a job. I thought it had to do with error view but now I don’t think so.
write-error "Test"
$ErrorView = 'DetailedView'
write-error "Test"
Get-Error
Get-Error | Write-Information
Get-Error | Out-String | Write-Information
Outputting errors just puts the message. No detailed info, no matter the error view. Outputting the error directly actually displays the whole object, including stack trace but piping it through the info stream causes it to go back to just a message.
If I use Out-String before passing it to the info stream, then it outputs the full object info again.
Test
Test
Exception :
Type : Microsoft.PowerShell.Commands.WriteErrorException
Message : Test
HResult : -2146233087
FullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,Errors.ps1
InvocationInfo :
MyCommand : Errors.ps1
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 1
Line : .
'C:\ProgramData\UniversalAutomation\Repository\Errors.ps1'
Statement : .
'C:\ProgramData\UniversalAutomation\Repository\Errors.ps1'
PositionMessage : At line:1 char:1
+ .
'C:\ProgramData\UniversalAutomation\Repository\Errors.ps1'
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : .
CommandOrigin : Internal
ErrorCategory_Activity : Write-Error
ErrorCategory_Reason : WriteErrorException
ErrorCategory_Message : NotSpecified: (:) [Write-Error],
WriteErrorException
ErrorDetails_ScriptStackTrace : at <ScriptBlock>,
C:\ProgramData\UniversalAutomation\Repository\Errors.ps1: line 3
at <ScriptBlock>, <No file>: line 1
CategoryInfo : NotSpecified: (:) [Write-Error],
WriteErrorException
ScriptStackTrace : at <ScriptBlock>,
C:\ProgramData\UniversalAutomation\Repository\Errors.ps1: line 3
at <ScriptBlock>, <No file>: line 1
Test
Exception :
Type : Microsoft.PowerShell.Commands.WriteErrorException
Message : Test
HResult : -2146233087
CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Errors.ps1
InvocationInfo :
MyCommand : Errors.ps1
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 1
Line : . 'C:\ProgramData\UniversalAutomation\Repository\Errors.ps1'
Statement : . 'C:\ProgramData\UniversalAutomation\Repository\Errors.ps1'
PositionMessage : At line:1 char:1
+ . 'C:\ProgramData\UniversalAutomation\Repository\Errors.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : .
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, C:\ProgramData\UniversalAutomation\Repository\Errors.ps1: line 3
at <ScriptBlock>, <No file>: line 1
It is correctly capturing the error stack trace in the error table.
Either way, I can get this fixed.