← Back to issue list

apt cache: improve error handling when packages do not have candidates available (CRAFT-136) (CRAFT-218)

View original Github issue

Metadata

Project
snapcraft
Number
#3528
Type
pull request
State
merged
Author
cjp256
Labels
Created
Updated
Closed

Current evaluation

Merged apt cache error handling that adds null checks for package candidates, preventing crashes when versions are unavailable. The change raises a clear PackageNotFoundError and optimizes unmarking logic, resolving multiple internal bug reports.

Suggested action:

No scores available.

Issue body

(1) Add some checks to ensure package.candidate is not None before using it. If it is None, when expected to not be None, raise a PackageNotFoundError with the name of the package in question. (2) Do not iterate over all packages when unmarking. This is the cause of https://forum.snapcraft.io/t/snapcraft-crash-when-esm-repositories-are-present/24587/8 where a package was being inspected that did not have an available candidate, causing Snapcraft to fail unnecessarily. Fixes SNAPCRAFT-2NE Fixes SNAPCRAFT-2H2 Fixes SNAPCRAFT-2BC Fixes SNAPCRAFT-277 Fixes SNAPCRAFT-263 Fixes SNAPCRAFT-1R4 Fixes SNAPCRAFT-1Q5 Fixes SNAPCRAFT-1DH Fixes a comment in unrelated bug report: LP: #1853682 Signed-off-by: Chris Patterson <chris.patterson@canonical.com> - [ ] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)? - [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [ ] Have you successfully run `./runtests.sh static`? - [ ] Have you successfully run `./runtests.sh tests/unit`? -----

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b Merged apt cache error handling that adds null checks for package candidates, preventing crashes when versions are unavailable. The change raises a clear PackageNotFoundError and optimizes unmarking logic, resolving multiple internal bug reports.
qwen3.6-35b-a3b-mtp-q6 Merged apt cache error handling improvements for packages lacking candidates. Adds None checks to raise PackageNotFoundError and optimizes iteration. Resolves multiple internal tickets and a Launchpad bug, verified by new spread tests.
qwen3.6-35b-a3b-mtp-q6 Merged fix for apt cache error handling when packages lack candidates. Added None checks to raise PackageNotFoundError and optimized unmarking. Resolved multiple SNAPCRAFT tickets and a Launchpad bug. Includes regression tests.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#648 Provide better errors for failures to clear the apt cache craft-parts open Request to wrap the apt-cache cleanup in craft_parts/packages/apt_cache.py with try/except to emit a clearer error when the cache cannot be removed (e.g. destructive mode run with sudo then without). Unlabeled, no maintainer response; related snapcraft issue closed as superseded by craft-application#974.
76%
#647 apt package cache marks packages that don't exist craft-parts open craft-parts marks a stage-package then fails with PackageNotFound, suspected stale apt cache or python-apt misuse; unreproducible. Maintainer noted in Feb 2026 it could be solved by PR #1446 (merged two-pass mark_packages fix).
71%