PowerShell / PowerShell/PSScriptAnalyzer
Transient RULE_ERROR
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
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:
Invoke-ScriptAnalyzer : Object reference not set to an instance of an object.
At /source/.build/Assert-ValidStyle.ps1:21 char:11
+ $issues = Invoke-ScriptAnalyzer -Path "$PSScriptRoot\.." -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (/source/.build/powershell-helpers.psm1:String) [Invoke-ScriptAnalyzer], NullReferenceException
+ FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
Contents of powershell-helpers.psm1:
# execute a command block and display stderr output without throwing powershell exceptions
# Taken from https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right
function Invoke-Script {
[CmdletBinding()]
[Alias('exec')]
param
(
[ScriptBlock] $ScriptBlock,
[string] $StderrPrefix = "",
[int[]] $AllowedExitCodes = @(0)
)
$backupErrorActionPreference = $script:ErrorActionPreference
$script:ErrorActionPreference = "Continue"
try {
& $ScriptBlock *>&1 | ForEach-Object -Process `
{
if ($_ -is [System.Management.Automation.ErrorRecord]) {
"$StderrPrefix$_"
}
else {
"$_"
}
}
if ($AllowedExitCodes -notcontains $LASTEXITCODE) {
throw "Execution failed with exit code $LASTEXITCODE"
}
}
finally {
$script:ErrorActionPreference = $backupErrorActionPreference
}
}
function Get-File {
param(
[string]$Uri,
[string]$Path,
[string]$Hash
)
New-Item -ItemType Directory -Path (Split-Path $path -Parent) -Force | Out-Null
Invoke-WebRequest -Uri $uri -OutFile $path
$actual = Get-FileHash -Path $path -Algorithm SHA256 | Select-Object -ExpandProperty Hash
if ($actual -ne $hash) {
throw "File $path with hash $actual doesn't match expected hash $hash"
}
}
function Invoke-InDirectory {
Param(
[ValidateScript( { Test-Path $_ -PathType Container } )]
[string]$Path,
[ValidateNotNullOrEmpty()]
[scriptblock]$ScriptBlock
)
Push-Location $Path
try {
&$ScriptBlock
}
finally {
Pop-Location
}
}
Export-ModuleMember -Alias * -Function *
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with .build/Assert-ValidStyle.ps1 and the Invoke-ScriptAnalyzer call, then inspect powershell-helpers.psm1 and the reported RULE_ERROR context. Try running the command against the repository with PowerShell 6.2.1 and PSScriptAnalyzer 1.18.3; done means identifying and preventing the intermittent null-reference failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100