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 committed Apr 23, 2024
1 parent a601e58 commit 86b3a74
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 86b3a74

Please sign in to comment.