question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running any pester tests shows Cannot read property '0' of undefined

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

Since recently (don’t know when) when I run/debug pester tests (even empty ones), I get this error.

Cannot read property '0' of undefined

I had this working for years without problem.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.62.3
ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
x64

Extension Version

ms-vscode.powershell@2021.10.2

Pester Version

5.3.1

Steps to Reproduce

I created a file foo.tests.ps1

[Run tests] | [Debug tests]
Describe 'meh' {

}

When I click any, I got that error.

I removed AppData\Roaming\Code and .vscode and it still happens.

Visuals

No response

Logs

Extension log
7.12.2021. 11:36:48 [NORMAL] - Visual Studio Code v1.62.3 64-bit
7.12.2021. 11:36:48 [NORMAL] - PowerShell Extension v2021.10.2
7.12.2021. 11:36:48 [NORMAL] - Operating System: Windows 64-bit
7.12.2021. 11:36:48 [NORMAL] - Language server starting --
7.12.2021. 11:36:48 [NORMAL] -     PowerShell executable: C:\Program Files\PowerShell\7\pwsh.exe
7.12.2021. 11:36:48 [NORMAL] -     PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.10.2' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\modules' -EnableConsoleRepl -StartupBanner '=====> PowerShell Integrated Console v2021.10.2 <=====
' -LogLevel 'Diagnostic' -LogPath 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\logs\1638873408-8b3ccd27-5ecb-412b-b618-3193cd3fdb981638873389306\EditorServices.log' -SessionDetailsPath 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\sessions\PSES-VSCode-16116-696739' -FeatureFlags @() 
7.12.2021. 11:36:48 [NORMAL] -     PowerShell Editor Services args: Import-Module 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.10.2' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\modules' -EnableConsoleRepl -StartupBanner '=====> PowerShell Integrated Console v2021.10.2 <=====
' -LogLevel 'Diagnostic' -LogPath 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\logs\1638873408-8b3ccd27-5ecb-412b-b618-3193cd3fdb981638873389306\EditorServices.log' -SessionDetailsPath 'c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\sessions\PSES-VSCode-16116-696739' -FeatureFlags @() 
7.12.2021. 11:36:48 [NORMAL] - pwsh.exe started.
7.12.2021. 11:36:48 [NORMAL] - Waiting for session file
7.12.2021. 11:36:50 [NORMAL] - Session file found
7.12.2021. 11:36:50 [NORMAL] - Registering terminal close callback
7.12.2021. 11:36:50 [NORMAL] - Registering terminal PID log callback
7.12.2021. 11:36:50 [NORMAL] - pwsh.exe PID: 8356
7.12.2021. 11:36:50 [NORMAL] - Language server started.
7.12.2021. 11:36:50 [NORMAL] - {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_kigvqssr.ns2","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_am5sbfhb.itf"}
7.12.2021. 11:36:50 [NORMAL] - Connecting to language service on pipe \\.\pipe\PSES_kigvqssr.ns2...
7.12.2021. 11:36:50 [NORMAL] - Language service connected.
exthost.log
[2021-12-07 11:36:30.011] [exthost] [info] Extension host with pid 14632 started
[2021-12-07 11:36:30.143] [exthost] [info] ExtensionService#_doActivateExtension vscode.microsoft-authentication, startup: false, activationEvent: 'onAuthenticationRequest:microsoft'
[2021-12-07 11:36:30.150] [exthost] [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch, startup: true, activationEvent: '*'
[2021-12-07 11:36:30.153] [exthost] [info] ExtensionService#_doActivateExtension vscode.git, startup: true, activationEvent: '*', root cause: vscode.github
[2021-12-07 11:36:30.317] [exthost] [info] ExtensionService#_doActivateExtension vscode.github, startup: true, activationEvent: '*'
[2021-12-07 11:36:30.334] [exthost] [info] Eager extensions activated
[2021-12-07 11:36:30.338] [exthost] [info] ExtensionService#_doActivateExtension vscode.merge-conflict, startup: false, activationEvent: 'onStartupFinished'
[2021-12-07 11:36:30.340] [exthost] [info] ExtensionService#_doActivateExtension ms-vscode-remote.remote-wsl-recommender, startup: false, activationEvent: 'onStartupFinished'
[2021-12-07 11:36:30.365] [exthost] [info] ExtensionService#_doActivateExtension vscode.github-authentication, startup: false, activationEvent: 'onAuthenticationRequest:github'
[2021-12-07 11:36:48.494] [exthost] [info] ExtensionService#_doActivateExtension ms-vscode.powershell, startup: false, activationEvent: 'onLanguage:powershell'
[2021-12-07 11:36:55.331] [exthost] [error] TypeError: Cannot read property '0' of undefined
	at I1.<anonymous> (c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:105:6685)
	at Generator.next (<anonymous>)
	at c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:1:970
	at new Promise (<anonymous>)
	at Ee (c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:1:790)
	at I1.launch (c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:105:6399)
	at I1.<anonymous> (c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:105:5538)
	at Generator.next (<anonymous>)
	at c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:1:970
	at new Promise (<anonymous>)
	at Ee (c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:1:790)
	at I1.launchTests (c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:105:5452)
	at c:\Users\mmilic\.vscode\extensions\ms-vscode.powershell-2021.10.2\out\main.js:105:5182
	at o._executeContributedCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:94:111751)
	at o._doExecuteCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:94:110639)
	at o.executeCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:94:110545)
	at v._executeConvertedCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:94:114105)
	at o._executeContributedCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:94:111751)
	at o.$executeContributedCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:94:112293)
	at n._doInvokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:98:13802)
	at n._invokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:98:13486)
	at n._receiveRequest (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:98:12148)
	at n._receiveOneMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:98:10826)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:98:8922
	at l.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:66:1712)
	at s.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:15990)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:30625
	at l.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:66:1712)
	at s.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:15990)
	at f._receiveMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:21260)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:18138
	at l.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:66:1712)
	at w.acceptChunk (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:13351)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:12699
	at Socket.m (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:13575)
	at Socket.emit (events.js:315:20)
	at addChunk (internal/streams/readable.js:309:12)
	at readableAddChunk (internal/streams/readable.js:284:9)
	at Socket.Readable.push (internal/streams/readable.js:223:10)
	at Pipe.onStreamRead (internal/stream_base_commons.js:188:23) PowerShell.RunPesterTests {"value":"ms-vscode.powershell","_lower":"ms-vscode.powershell"}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andschwacommented, Dec 15, 2021

That makes sense! Ok, this is a bug. When no workspaces are open, the indexing there on workspaceFolders throws. I’ll get it fixed, thanks for the issue.

0reactions
majkinetorcommented, Dec 15, 2021

No I don’t.

I just tried it now and it works normally when I run it within a workspace.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property '0' of undefined (only on unit test)
This error is showed only on the karma logs. But it shouldn't be undefined because of a loop condition. In the tools.js file...
Read more >
pester/Pester - Gitter
Hi there, since recently I cant execute tests from vscode, I get this when I click any run/debug. image.png. Cannot read property '0'...
Read more >
Just started on unit testing, stuck on an issue that I have no ...
I believe the reason it is showing the Cannot read property 'subscribe' of undefined is because the folder$ is null in the test...
Read more >
Quick Start - Pester
Pester tests can execute any command or script that is accessible to a Pester test file. This includes functions, Cmdlets, Modules and scripts....
Read more >
Pester.psm1 5.1.0-rc1 - PowerShell Gallery
looks for a property on object that might be null ... running in discovery mode se we can change ... throw "Test cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found