Repository navigation
Transient RULE_ERROR #1351
Description
Activity
Chris Kuech (@chriskuech) I have also been getting this for a while. It's is flaky.
I have
Invoke-PSScriptAnalyzerincluded in a Azure Pipeline as part of a CI process. Sometimes it will fail/ sometimes not. Even on the same code base (git commit). So often I'll just rerun the build and it works.I've noticed the issue from v1.18.0 and still getting the issue on v1.18.3 as well.
The issue mostly happens on a MacOS build, however it also happens on Windows with PowerShell Core. Both running 6.2.3. Although I have noticed the issue on previous 6.2.x versions.
I've been holding off logging an issue until I had a little more information. Previously I though it was specific rules. But I managed to get a stack trace. When running locally.
Name Value ---- ----- PSVersion 6.2.3 PSEdition Core GitCommitId 6.2.3 OS Microsoft Windows 10.0.18363 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0PS> $error[0].exception Object reference not set to an instance of an object. PS> $error[0].exception.stacktrace at System.Management.Automation.CommandInfo.ResolveParameter(String name) at Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetExportedFunction(Ast ast) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidReservedCharInCmdlet.AnalyzeScript(Ast ast, String fileName)+MoveNext() at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass82_1.<AnalyzeSyntaxTree>b__2()I notice this has only happened to us when importing *.psm1 files that contain
Export-ModuleMember.@BernieWhite , can you say the same?
Reacted by Elinora WhiteI found that you can repro this issue locally after a long time. I ran it in a loop in a new powershell session and finally reproed it after 25 tries.
1..100 | % {pwsh .\my-psscriptanalyzer-runner.ps1}
I found that after removing all calls to
Export-ModuleMember, I no longer see issues even after hundreds of trials.Reacted by Elinora WhiteChris Kuech (@chriskuech) interesting, I did bulk testing in the same PowerShell process and the issue doesn't predictably reoccur. Can't say on what happens without
Export-ModuleMemberbecause I haven't done any testing, but confirming that my module does useExport-ModuleMember.bergmeister commented
on Dec 10, 2019 CollaboratorMore actionsChris Kuech (@chriskuech) When it happens, can you please also report
$error[0].exception.stacktrace. If you have it in your foreach loop, you might have to try to catch it and then report the exception stack trace in the catch block. Also please report the used PowerShell versions as the exception reported by @BernieWhite originates from within PowerShell itself.Reacted by Elinora WhiteHere's my
$PSVersionTable:Name Value ---- ----- PSVersion 6.2.3 PSEdition Core GitCommitId 6.2.3 OS Microsoft Windows 10.0.18363 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0I made a minimal repro. When I run the repro, I always eventually get the same error, but not always the same stack trace.
# repro.ps1 for ($i = 1; $true; $i++) { Write-Host "`rAttempt $i" -NoNewLine pwsh -c 'Invoke-ScriptAnalyzer . -Recurse | Out-Null; if (-not $?) {$Error[0].Exception.StackTrace}' } # module.psm1 function f() { } Export-Module -Function *
These are the two main stack traces I saw:
at System.Management.Automation.CommandInfo.ResolveParameter(String name) at Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetExportedFunction(Ast ast) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.ProvideCommentHelp.AnalyzeScript(Ast ast, String fileName)+MoveNext() at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass82_1.<AnalyzeSyntaxTree>b__2() at System.Management.Automation.CommandInfo.ResolveParameter(String name) at Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetExportedFunction(Ast ast) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidReservedCharInCmdlet.AnalyzeScript(Ast ast, String fileName)+MoveNext() at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass82_1.<AnalyzeSyntaxTree>b__2()Have this bug. Running PSScriptAnalyzer 1.22 directly on my AzDO build agent server in PS 5.1 on Windows 10.
I can reproduce this on:
- PowerShell: 7.4.10
- PSEdition: Core
- OS: Ubuntu 24.04.4 LTS
- PSScriptAnalyzer: 1.25.0
Minimal repro:
module.psm1function Get-Foo { } Export-ModuleMember -Function *
Run repeatedly in fresh
pwshprocesses:tmpdir=$(mktemp -d) printf 'function Get-Foo { }\n\nExport-ModuleMember -Function *\n' > "$tmpdir/module.psm1" for i in $(seq 1 100); do PSSA_TMP="$tmpdir" pwsh -NoProfile -Command ' $ErrorActionPreference = "Stop" Invoke-ScriptAnalyzer -Path $env:PSSA_TMP -Recurse -ErrorAction Stop | Out-Null ' || break done
On my machine this failed by attempt 10 with:
System.NullReferenceException: Object reference not set to an instance of an object. at System.Management.Automation.CommandInfo.ResolveParameter(String name) at Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetExportedFunction(Ast ast) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.ProvideCommentHelp.AnalyzeScript(Ast ast, String fileName)+MoveNext() at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass84_1.<AnalyzeSyntaxTree>b__2()Removing
Export-ModuleMemberfrom the same minimal module ran 100 fresh attempts cleanly.
I wish I could provide more information, but the error is transient and therefore cannot be deterministically reproed.
PowerShell version: 6.2.1
PSScriptAnalyzer version: 1.18.3
OS Version: Ubuntu 1604
PSScriptAnalyzer is failing occasionally with the following error:
Contents of powershell-helpers.psm1: