Skip to content

Ensure checksums are always defined when requested#61

Open
Thilas wants to merge 1 commit intochocolatey-community:developfrom
Thilas:checksum
Open

Ensure checksums are always defined when requested#61
Thilas wants to merge 1 commit intochocolatey-community:developfrom
Thilas:checksum

Conversation

@Thilas
Copy link

@Thilas Thilas commented May 23, 2024

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

  • Windows 11
  • Windows Server 2022

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v2 compatibility checked?

Related Issue

Supersedes #30

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (!$global:Latest.Item('Checksum' + $a)) {
if (-not $global:Latest.ContainsKey('Checksum' + $a)) {

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +160
# Sanity check: ensure checksum is defined (rare bug!)
if (!$global:Latest.Item('Checksum' + $a)) {
throw "Hash for $a bit version is missing."
}
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants