PowerShell / PowerShell/vscode-powershell

Error: The scope number '7' exceeds the number of active scopes. Parameter name: ScopeID

Open
#1,856 18 comments 1 reaction 1 assignee View on GitHub

@andyleejordan is already working on this.

Since Nov 5, 2021.

Area-Documentation Area-PSReadLine Area-Threading Issue-Bug
Dominant language
TypeScript
Stars
1.9k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

System Details
### VSCode version: 1.34.0-insider 56f1b4795fed05677eb82a21dac4fc1ab62d747b
x64

### VSCode extensions:
ms-vscode.powershell@1.12.0
ms-vscode.powershell-preview@2.0.1
ritwickdey.LiveServer@5.5.1


### PSES version: 2.0.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Issue Description

Sometimes I receive the following error:

[-] should be green 15.49s
ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
ParameterBindingValidationException: Cannot validate argument on parameter 'Message'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
at , S:\Test\Script.ps1: line 5

Script.ps1

$Error.Clear()

if ($Error) {
    $Error.ForEach( {
            Write-EventLog @EventErrorParams -Message $_.Exception.Message
        })
}

Script.Tests.ps1

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'

$Error.Clear()

Describe $sut {
    Mock Write-EventLog

    It 'should be green' {
        ."$here\$sut"
        $Error | Should -BeNullOrEmpty
    }
    In $TestDrive {
        Describe 'Test' {
            It 'should be green' {
                ."$here\$sut"
                $Error | Should -BeNullOrEmpty
            }
        }
    }
}

This does not always happen and it took me a long time to figure out that this only happens in VS Code and never in the PowerShell ISE. To narrow it further down the behavior can be consistently reproduced when setting a breakpoint at the line if ($Error).

When consulting the array of $Error at the breakpoint the following is shown:
image

I don;t know why this happens, but it could be related to #66. I'm using the PowerShell Preview 2.0.1.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.