Skip to content

Commit

Permalink
Handle errors in mod tidy script (#22234)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbp authored Jan 11, 2024
1 parent 4b274bc commit c99ab58
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions eng/scripts/modtidy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ Param(

$modFiles = Get-ChildItem -Path $searchPath -Include "go.mod" -Recurse

$modFiles | ForEach-Object -Parallel {
Push-Location $_.Directory
$tidyErrors = $modFiles | ForEach-Object -Parallel {
Set-Location $_.Directory
Write-Host (Get-Location)
go mod tidy
Pop-Location
$output = go mod tidy 2>&1
if ($LASTEXITCODE) {
exit 1
return @{ Directory = $_.Directory; Output = $output }
}
}

if ($tidyErrors) {
Write-Error "Encountered the following tidy failures:" -ErrorAction 'Continue'
foreach ($err in $tidyErrors) {
Write-Host "=== $($err.Directory) ==="
$err.Output
}
exit 1
}

0 comments on commit c99ab58

Please sign in to comment.