PowerShell / PowerShell/PSScriptAnalyzer
Transient RULE_ERROR
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 2.2k
- Fork
- 414
- Merge trung bình
- 13 giờ 1 phút
- Pull request đã merge (30 ngày)
- 2
Mô tả
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 *
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với .build/Assert-ValidStyle.ps1 và lệnh gọi Invoke-ScriptAnalyzer, sau đó kiểm tra powershell-helpers.psm1 và ngữ cảnh RULE_ERROR được báo cáo. Hãy thử chạy lệnh trên repository bằng PowerShell 6.2.1 và PSScriptAnalyzer 1.18.3; hoàn thành khi đã xác định và ngăn chặn được lỗi tham chiếu null xảy ra không liên tục.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- powershell
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100