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 @@ -1226,7 +1226,7 @@ function Get-ConciseViewPositionMessage {
$reason = 'Exception'
}
# MyCommand can be the script block, so we don't want to show that so check if it's an actual command
elseif ($myinv.MyCommand -and (Get-Command -Name $myinv.MyCommand -ErrorAction Ignore))
elseif ($myinv.MyCommand -and $myinv.MyCommand.Name -and (Get-Command -Name $myinv.MyCommand -ErrorAction Ignore))
{
$reason = $myinv.MyCommand
}
Expand Down
14 changes: 14 additions & 0 deletions test/powershell/engine/Formatting/ErrorView.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ Describe 'Tests for $ErrorView' -Tag CI {
$e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' 2>&1 | Out-String
$e | Should -BeLike "*cmdletThatDoesntExist*"
}

It "Error shows for advanced function" {
# need to have it virtually interactive so that InvocationInfo.MyCommand is empty
$e = '[cmdletbinding()]param()$pscmdlet.writeerror([System.Management.Automation.ErrorRecord]::new(([System.NotImplementedException]::new("myTest")),"stub","notimplemented","command"))' | pwsh -noprofile -file - 2>&1 | Out-String
$e | Should -Not -BeNullOrEmpty

# need to see if ANSI escape sequences are in the output as ANSI is disabled for CI
if ($e.Contains("`e")) {
$e | Should -BeLike "*: `e*myTest*"
}
else {
$e | Should -BeLike "*: myTest*"
}
}
}

Context 'NormalView tests' {
Expand Down