Vscode-powershell: $ErrorActionPreference = 'stop' not showing the ERROR

Created on 23 Mar 2020  ·  9Comments  ·  Source: PowerShell/vscode-powershell

Hi
$ErrorActionPreference = 'stop'
in vscode causes the script to stop without throwing the ERROR code to Display when running with F5.

eg:
Script:
$ErrorActionPreference = 'stop'
write-WrongCommandLine "foo"
Write-Host 'Hello World'

Output vscode:
nothing, but the script stops as wanted
Output ISE and wanted
write-WrongCommandLine : The term 'write-WrongCommandLine' is not recognized as the name of a cmdle….
and the script stops

Resolution-Fixed

Most helpful comment

thank you

All 9 comments

Sounds like what I ran into in #2565. Are you running the stable extension?

Yes stable ver 5.1

Can you give this a go in the PowerShell Preview extension? This should be fixed in that.

You can still use whatever version of PowerShell you'd like. This is the Preview build of the _vs code extension_.

the preview Works as I liked 👍

Great! I'll close this now since it's just pending a new release of the stable extension

thank you

I just ran into this today and noticed that it was only affecting PowerShell 7; PowerShell 5.1 still displayed the error fine. Switching from the PowerShell VS Code extension to the PowerShell Preview extension has fixed the issue 👍

I'll also point out here that the Azure DevOps PowerShell extension has a similar bug in it when using Pwsh currently, and I've reported that issues here.

I'll also point out here that the Azure DevOps PowerShell extension has a similar bug in it when using Pwsh currently, and I've reported that issues here.

Given the nature of the fix here (which was to solve a race condition in the way errors were printed), it's likely that the two are unrelated.

Was this page helpful?
0 / 5 - 0 ratings