The current formatting of ErrorRecord isn't useful enough for developers and too much unactionable
content for regular end users. Proposal on how to fix this will end up being a RFC, but we can discuss it here first. Perhaps the verbosity of the format is user-settable. There is also the problem of special casing formatting of ErrorRecord.
# part 1
PS C:\Users\slee\repos\PowerShell> 1/0
# part 2
PS C:\Users\slee\repos\PowerShell> $error[0] | fl
# part 1
# not sure what a good message would be for end users, but keeping it simple
Attempted to divide by zero.
At line:1 char:1
+ 1/0
# part 2 (requires -f)
PS C:\Users\slee\repos\PowerShell> $error[0] | fl -f
Exception : System.Management.Automation.RuntimeException: Attempted to divide by zero. --->
System.DivideByZeroException: Attempted to divide by zero.
--- End of inner exception stack trace ---
at System.Management.Automation.IntOps.Divide(Int32 lhs, Int32 rhs)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1
arg1)
at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
TargetObject :
CategoryInfo : NotSpecified: (:) [], RuntimeException
FullyQualifiedErrorId : RuntimeException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails :
# part 1
Attempted to divide by zero.
At line:1 char:1
+ 1/0
+ ~~~
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
# part 2
PS C:\Users\slee\repos\PowerShell> $error[0] | fl
Attempted to divide by zero.
At line:1 char:1
+ 1/0
+ ~~~
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Name Value
---- -----
PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.6
OS Microsoft Windows 10.0.16350
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
@SteveL-MSFT: This is essentially what #3647 is about.
I was about to post something there. Do you want us to continue here instead?
I whole heartedly agree.
BTW for script developers, I'd love to see something like Jeffrey's old Resolve-ErrorRecord
(which we ship in PSCX) come built-in. This gives much more (hopefully useful) info for developers:
4:5ms> Resolve-ErrorRecord
PSMessageDetails :
Exception : System.Management.Automation.RuntimeException: Attempted to divide by zero. --->
System.DivideByZeroException: Attempted to divide by zero.
--- End of inner exception stack trace ---
at System.Management.Automation.IntOps.Divide(Int32 lhs, Int32 rhs)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1
arg1)
at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
TargetObject :
CategoryInfo : NotSpecified: (:) [], RuntimeException
FullyQualifiedErrorId : RuntimeException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
MyCommand :
BoundParameters : {}
UnboundArguments : {}
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : -1
ScriptName :
Line : 1/$x
PositionMessage : At line:1 char:1
+ 1/$x
+ ~~~~
PSScriptRoot :
PSCommandPath :
InvocationName :
PipelineLength : 0
PipelinePosition : 0
ExpectingInput : False
CommandOrigin : Internal
DisplayScriptPosition :
Exception at nesting level 0 ---------------------------------------------------
ErrorRecord : Attempted to divide by zero.
WasThrownFromThrowStatement : False
Message : Attempted to divide by zero.
Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException : System.DivideByZeroException: Attempted to divide by zero.
TargetSite : System.Object Divide(Int32, Int32)
StackTrace : at System.Management.Automation.IntOps.Divide(Int32 lhs, Int32 rhs)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0
arg0, T1 arg1)
at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
retedFrame frame)
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
Exception at nesting level 1 ---------------------------------------------------
Message : Attempted to divide by zero.
Data : {}
InnerException :
TargetSite :
StackTrace :
HelpLink :
Source :
HResult : -2147352558
@mklement0 I'll resolve this as a dupe of yours https://github.com/PowerShell/PowerShell/issues/3647
Most helpful comment
I whole heartedly agree.
BTW for script developers, I'd love to see something like Jeffrey's old
Resolve-ErrorRecord
(which we ship in PSCX) come built-in. This gives much more (hopefully useful) info for developers: