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 @@ -1104,6 +1104,15 @@ function Get-ConciseViewPositionMessage {
if ($_.Exception -and $_.Exception.WasThrownFromThrowStatement) {
$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))
{
$reason = $myinv.MyCommand
}
# If it's a scriptblock, better to show the command in the scriptblock that had the error
elseif ($_.CategoryInfo.Activity) {
$reason = $_.CategoryInfo.Activity
}
elseif ($myinv.MyCommand) {
$reason = $myinv.MyCommand
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Describe "Stream writer tests" -Tags "CI" {
It "Should write error messages to the error stream" {
Write-Error "Testing Error" 2>&1 > $targetfile
# The contents of the error stream should contain the expected text
$targetfile | Should -FileContentMatch ": Testing Error"
$targetfile | Should -FileContentMatch "Testing Error"
}

It "Should write debug messages to the debug stream" {
Expand Down
12 changes: 12 additions & 0 deletions test/powershell/engine/Formatting/ErrorView.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,17 @@ Describe 'Tests for $ErrorView' -Tag CI {
Start-Job -ScriptBlock { get-item (new-guid) } | Wait-Job | Receive-Job -ErrorVariable e -ErrorAction SilentlyContinue
($e | Out-String).Trim().Count | Should -Be 1
}

It "Activity shows up correctly for scriptblocks" {
$e = pwsh -noprofile -command 'Write-Error 'myError' -ErrorAction SilentlyContinue; $error[0] | Out-String'
[string]::Join('', $e).Trim() | Should -BeLike "*Write-Error:*myError*" # wildcard due to VT100
}

It "Function shows up correctly" {
function test-myerror { [cmdletbinding()] param() write-error 'myError' }

$e = pwsh -noprofile -command 'function test-myerror { [cmdletbinding()] param() write-error "myError" }; test-myerror -ErrorAction SilentlyContinue; $error[0] | Out-String'
[string]::Join('', $e).Trim() | Should -BeLike "*test-myerror:*myError*" # wildcard due to VT100
}
}
}