← Back to issue list

repo: catch error updating the package cache

View original Github issue

Metadata

Project
snapcraft
Number
#2079
Type
pull request
State
merged
Author
kalikiana
Labels
Created
Updated
Closed

Current evaluation

Merged. Catches apt package cache update errors like hash mismatches and host resolution failures. Fixes #2029, #2030, and LP: #1747715 by handling exceptions, clearing the index on hash failures, and allowing Snapcraft to proceed. Includes test updates.

Suggested action:

No scores available.

Issue body

- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)? - [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)? - [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)? - [x] Have you successfully run `./runtests.sh static`? - [x] Have you successfully run `./runtests.sh unit`? ----- This PR handles errors when updating the package cache, such as a hash mismatch or unresolved hostnames. The apt API doesn't distinguish these, so unfortunately we can't be very specific here but need to rely on the output we get before the error is raised. If the error is a hashsum mismatch, the index will be cleared and Snapcraft will continue. Fixes: #2029 #2030 Fixes: [LP: #1747715](https://bugs.launchpad.net/snapcraft/+bug/1747715) The following tests are added/ modified: - tests.unit.test_errors - To verify CacheUpdateFailedError - tests.unit.repo.test_deb.UbuntuTestCase.test_cache_update_failed - To verify that an `apt.cache.FetchFailedException` is handled as a proper error. - tests.unit.repo.test_deb.UbuntuTestCase.test_cache_hashsum_mismatch - To verify that a hashsum error will be caught and proceed after clearing the index. I locally ran the tests: - `./runtests.sh tests/unit` with unrelated failures in [tests.unit.test_lifecycle.CoreSetupTestCase.test_core_setup_if_docker_env](https://bugs.launchpad.net/snapcraft/+bug/1752576), `tests.unit.test_mangling.TestClearExecstack.test_execstack_clears` and `tests.unit.test_elf`. - `./runtests.sh tests/integration` with one unrelated failure in [tests.integration.general.test_parser.TestParserWikis](https://bugs.launchpad.net/snapcraft/+bug/1752580) - `./runtests.sh static`: Everything passed Manual test steps: - cd tests/integration/snaps/go-hello - Add a stage package: stages-packages: [appstream] - Modify `/etc/apt/sources.list` so that it can't update successfully, such as by adding an invalid URL. - snapcraft - Observe the error "Failed to update the package cache: Some files could not be downloaded. Check that the sources on your host are configured correctly.".

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b Merged. Catches apt package cache update errors like hash mismatches and host resolution failures. Fixes #2029, #2030, and LP: #1747715 by handling exceptions, clearing the index on hash failures, and allowing Snapcraft to proceed. Includes test updates.
qwen3.6-35b-a3b-mtp-q6 Merged fix that catches package cache update errors like hash mismatches and host resolution failures. It clears the index on hash mismatches to allow continuation, adds unit tests, and resolves #2029, #2030, and LP: #1747715.
qwen3.6-35b-a3b-mtp-q6 Merged implementation that catches package cache update errors including hash mismatches and unresolved hostnames. Clears the index on hashsum failures and proceeds. Resolves #2029, #2030, and LP: #1747715 with added unit tests.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#1499 repo: make errors based on SnapcraftError snapcraft merged Merged a fix preventing repo-based errors from triggering tracebacks outside debug mode by inheriting from SnapcraftError. Approved by two reviewers, passed CI, and resolves an oversight from PR #1436.
73%
#1815 repo: handle invalid snaps snapcraft merged Merged changes handling invalid snaps in build-snaps with a clear error message. Adds retries to information fetching for improved network failure debugging. Approved after resolving a minor CI typo.
72%
#2513 repo: handle deb package fetch error snapcraft merged Merged after approval and CI checks. Implements graceful error handling for failed deb package fetches to prevent crashes, resolving SNAPCRAFT-JE and SNAPCRAFT-JF. Includes copyright date updates.
72%
#3983 repo: raise error when populating the apt cache directory fails snapcraft merged Merged. Adds a helpful error when copying /etc/apt to the cache directory fails, resolving CRAFT-1421. Handles Ubuntu Pro and destructive mode edge cases without root privileges. Approved by two reviewers and passed CI.
71%
#43 packages: add support to apt cache operations craft-parts merged Merged PR adding apt cache operations for package retrieval. Approved by two reviewers and passed CI. Follows snapcraft standards and is planned for future migration to a separate project.
70%