Skip to content

Commit

Permalink
Add a max. of 3 retries for Invoke-ScriptAnalyzer per each file that …
Browse files Browse the repository at this point in the history
…causes an exception
  • Loading branch information
tteguayco committed Oct 25, 2023
1 parent 487a0a4 commit d4f00f8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,35 @@ $analyzerParameters = @{
IncludeDefaultRules = $true
Fix = $Fix
}
$maxRetries = 3
$results = Find-Recursively -IncludeFile '*.ps1', '*.psm1', '*.psd1' -ExcludeDirectory node_modules |
Where-Object { # Exclude /TestSolutions/Violate-Analyzers.ps1 and /TestSolutions/*/Violate-Analyzers.ps1
$IncludeTestSolutions -or -not (
$PSItem.Name -eq 'Violate-Analyzers.ps1' -and
($PSItem.Directory.Name -eq 'TestSolutions' -or $PSItem.Directory.Parent.Name -eq 'TestSolutions')) } |
ForEach-Object { Invoke-ScriptAnalyzer -Path $PSItem.FullName @analyzerParameters }
ForEach-Object {
$retryCount = 0
while ($retryCount -lt $maxRetries)
{
try
{
Invoke-ScriptAnalyzer -Path $PSItem.FullName @analyzerParameters
break
}
catch
{
$retryCount++
if ($retryCount -eq $maxRetries)
{
Write-Error "Failed to analyze $($PSItem.FullName) after $maxRetries attempts. Exception: $_"
}
else
{
Write-Error "Retry #$($retryCount): An exception occurred: $_. Retrying..."
}
}
}
}

foreach ($result in $results)
{
Expand Down

0 comments on commit d4f00f8

Please sign in to comment.