Skip to content

Commit

Permalink
(chocolatey#3327) Improves initialization handling
Browse files Browse the repository at this point in the history
Won't run in environments where DotNet 4.8 has been installed where
running in PS<=3, due to the issues found when testing in those
environments.

Also improves the handling of errors, as previously we were never
"reaching" an error due to the way Choco CLI's streams and exit codes
work out.
  • Loading branch information
JPRuskin authored and gep13 committed Apr 24, 2024
1 parent 1717475 commit 547dab9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -834,17 +834,27 @@ function Install-DotNet48IfMissing {
}

function Invoke-Chocolatey-Initial {
if ($PSVersionTable.Major -le 3 -and $script:DotNetInstallRequiredReboot) {
Write-Debug "Skipping initialization due to known issues before rebooting."
return
}

Write-Debug "Initializing Chocolatey files, etc by running Chocolatey CLI..."

try {
$chocoInstallationFolder = Get-ChocolateyInstallFolder
$chocoExe = Join-Path -Path $chocoInstallationFolder -ChildPath "choco.exe"
$runResult = & $chocoExe -v
Write-Debug "Chocolatey CLI execution completed successfully."
$runResult = & $chocoExe -v *>&1
if ($LASTEXITCODE -eq 0) {
Write-Debug "Chocolatey CLI execution completed successfully."
}
else {
throw
}
}
catch {
Write-ChocolateyWarning "Unable to run Chocolatey CLI at this time:`n$($runResult)"
}
}

Export-ModuleMember -Function Initialize-Chocolatey;
Export-ModuleMember -Function Initialize-Chocolatey

0 comments on commit 547dab9

Please sign in to comment.