Ensure checksums are always defined when requested#61
Ensure checksums are always defined when requested#61Thilas wants to merge 1 commit intochocolatey-community:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a sanity check to ensure that checksums are always defined when requested, addressing a rare bug where checksums could be missing despite automatic calculation. The changes include improved logging for hash checking operations and better exception handling.
Key Changes
- Added logging message to indicate when hash checking begins for each architecture
- Improved exception re-throwing to preserve stack trace information
- Added validation check to ensure checksums are defined after processing
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| } | ||
| # Sanity check: ensure checksum is defined (rare bug!) | ||
| if (!$global:Latest.Item('Checksum' + $a)) { |
There was a problem hiding this comment.
Using Item() will throw an exception if the key doesn't exist in the hashtable. This should use ContainsKey() instead to properly check if the checksum was defined. The current code will fail with a key not found error instead of the intended error message on line 159.
| if (!$global:Latest.Item('Checksum' + $a)) { | |
| if (-not $global:Latest.ContainsKey('Checksum' + $a)) { |
| # Sanity check: ensure checksum is defined (rare bug!) | ||
| if (!$global:Latest.Item('Checksum' + $a)) { | ||
| throw "Hash for $a bit version is missing." | ||
| } |
There was a problem hiding this comment.
The new checksum sanity check should have test coverage to verify it correctly catches cases where checksums are missing. Consider adding a test that simulates the rare bug where the chocolateyInstall.ps1 script completes without throwing the expected 'au_break:' exception.
Description Of Changes
Throws an error in case a requested checksum is missing.
Motivation and Context
I don't really understand why but using AU, I ended once having no checksums even though they are usually always automatically calculated by AU.
This change is meant to catch this issue as early as possible.
Testing
N/A
Operating Systems Testing
Change Types Made
Change Checklist
Related Issue
Supersedes #30