PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.85k stars 375 forks source link

Index out of range Error for ScriptDefinition '$a=1' on pwsh 6.1.0.-preview.1 only #973

Open kalgiz opened 6 years ago

kalgiz commented 6 years ago

Steps to reproduce

Invoke-scriptanalyzer -script '$a=1'

Expected behavior

Triggers PSUseDeclaredVarsMoreThanAssignments rule.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
out-lineoutput : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
+ CategoryInfo          : NotSpecified: (:) [out-lineoutput], ArgumentOutOfRangeException
+ FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.PowerShell.Commands.OutLineOutputCommand

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.1
PSEdition                      Core
GitCommitId                    v6.1.0-preview.1
OS                             Linux 4.13.0-38-generic #43~16.04.1-Ubuntu SMP Wed Mar 14 17:48:43 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.16.1
bergmeister commented 6 years ago

@kalgiz This is interesting because I have the same version of Ubuntu and using PowerShell Core version is 6.0.2 this did not happen at first, but when I upgraded to 6.1.0-preview.1 it started to happen. I was wondering a few days ago if we should run CI also against the preview of PSCore and this might be good idea to have at least a PR for it to be alerted about upcoming issues. I ran the test suite locally on 6.1.0-preview1 and there were only the 9 known failures btw. I opened PR 974 for that. It would be good to also see the stack trace. If it is an error that bubbles up to PowerShell, then you can get more details e.g. via $error[0] | select *, otherwise you need to attach the debugger (and possibly change the exception settings to break on any exception). I suspect that this could also be one of the known concurrency issues that are mostly due to the static members in the Helper class. I tagged other issues with the new Issue -Concurrency label so that you can have a look at them as well. I think there are a couple of underlying problems in the code that cause those exceptions. To give you some background: PSSA spawns a new thread for each rule.

bergmeister commented 6 years ago

@kalgiz To add more details: this also happens for pwsh 6.1.0.-preview.1 on Windows as well (but not on 6.0.2 or 5.1). The good news is that this happens only with the currently released version of PSSA but not the latest development version (I re-tested on Windows and Ubuntu). Can you confirm that this does bug does not happen when building PSSA using the latest version of PSSA? I think we could close it then.