Powershell: ErrorRecord์˜ ๊ธฐ๋ณธ ํ˜•์‹ ๋‹ค์‹œ ๋ณด๊ธฐ

์— ๋งŒ๋“  2017๋…„ 08์›” 25์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: PowerShell/PowerShell

ErrorRecord์˜ ํ˜„์žฌ ํ˜•์‹์€ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ์ถฉ๋ถ„ํžˆ ์œ ์šฉํ•˜์ง€ ์•Š์œผ๋ฉฐ ๋„ˆ๋ฌด ๋งŽ์ด ์‹คํ–‰ ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
์ผ๋ฐ˜ ์ตœ์ข… ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•œ ์ฝ˜ํ…์ธ . ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ œ์•ˆ์€ ๊ฒฐ๊ตญ RFC๊ฐ€ ๋˜์ง€๋งŒ ๋จผ์ € ์—ฌ๊ธฐ์—์„œ ๋…ผ์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋งˆ๋„ ํ˜•์‹์˜ ์ž์„ธํ•œ ์ •๋„๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 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

Issue-Discussion Issue-Enhancement Resolution-Duplicate WG-Engine

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์ „์ ์œผ๋กœ ๋™์˜ํ•ฉ๋‹ˆ๋‹ค.

์Šคํฌ๋ฆฝํŠธ ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ BTW, ์ €๋Š” Jeffrey์˜ ์˜ค๋ž˜๋œ Resolve-ErrorRecord (PSCX๋กœ ๋ฐฐ์†ก๋จ)์™€ ๊ฐ™์€ ๊ฒƒ์ด ๋‚ด์žฅ๋œ ๊ฒƒ์„ ๋ณด๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ํ›จ์”ฌ ๋” ๋งŽ์€ (์œ ์šฉํ•œ) ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

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

๋ชจ๋“  3 ๋Œ“๊ธ€

@SteveL-MSFT: ์ด๊ฒƒ์€ ๋ณธ์งˆ์ ์œผ๋กœ #3647์— ๊ด€ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋‚˜๋Š” ๊ฑฐ๊ธฐ์— ๋ญ”๊ฐ€๋ฅผ ๊ฒŒ์‹œํ•˜๋ ค๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  ์—ฌ๊ธฐ์—์„œ ๊ณ„์†ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?

์ „์ ์œผ๋กœ ๋™์˜ํ•ฉ๋‹ˆ๋‹ค.

์Šคํฌ๋ฆฝํŠธ ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ BTW, ์ €๋Š” Jeffrey์˜ ์˜ค๋ž˜๋œ Resolve-ErrorRecord (PSCX๋กœ ๋ฐฐ์†ก๋จ)์™€ ๊ฐ™์€ ๊ฒƒ์ด ๋‚ด์žฅ๋œ ๊ฒƒ์„ ๋ณด๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ํ›จ์”ฌ ๋” ๋งŽ์€ (์œ ์šฉํ•œ) ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

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 ๋‹น์‹ ์˜ ์†์ž„์ˆ˜๋กœ ์ด๊ฒƒ์„ ํ•ด๊ฒฐํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค https://github.com/PowerShell/PowerShell/issues/3647

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰