Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
'System.Management.Automation.InvocationInfo'
)

# if object is an Exception, add an ExceptionType property
if ($obj -is [Exception]) {
$obj | Add-Member -NotePropertyName Type -NotePropertyValue $obj.GetType().FullName -ErrorAction Ignore
}

# first find the longest property so we can indent properly
$propLength = 0
foreach ($prop in $obj.PSObject.Properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,24 @@ Describe 'Get-Error tests' -Tag CI {
$out | Should -BeLikeExactly '*ExpectedValueExpression*'
$out | Should -BeLikeExactly '*UnexpectedToken*'
}

It 'Get-Error adds ExceptionType for Exceptions' {
try {
[System.Net.DNS]::GetHostByName((New-Guid))
}
catch {
}

$out = Get-Error | Out-String
$out | Should -BeLikeExactly '*Type*'

if ($IsWindows) {
$expectedExceptionType = "System.Management.Automation.ParentContainsErrorRecordException"
}
else {
$expectedExceptionType = "System.Net.Internals.SocketExceptionFactory+ExtendedSocketException"
}

$out | Should -BeLikeExactly "*$expectedExceptionType*"
}
}