PowerShell / PowerShell/PSScriptAnalyzer

Transient RULE_ERROR

Ouverte
#1,351 9 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Area - Rules Issue - Bug
Langage dominant
C#
Étoiles
2.2k
Forks
414
Merge moyen
13 h 1 min
PR mergées (30 j)
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 *

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par .build/Assert-ValidStyle.ps1 et l’appel à Invoke-ScriptAnalyzer, puis examinez powershell-helpers.psm1 et le contexte RULE_ERROR signalé. Essayez d’exécuter la commande sur le dépôt avec PowerShell 6.2.1 et PSScriptAnalyzer 1.18.3 ; le travail est terminé lorsque l’échec intermittent de référence nulle a été identifié et empêché.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
powershell
Domaine
devtools
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.