Provide better errors for failures to clear the apt cache
Metadata
Current evaluation
Superseded by snapcraft 8.14, which now warns when running destructive mode as a non-root user. The related improvement was merged in canonical/craft-application#974, providing clearer guidance for cache permission issues.
Suggested action: —
No scores available.
Issue body
### What needs to get done
The apt cache may fail to be removed when snapcraft is run in destructive-mode as root, then not as root.
Snapcraft should provide a better error for when the apt-cache cannot be removed.
This can be done by wrapping [this block](https://github.com/snapcore/snapcraft/blob/89961cfc3a9f93b3fe551711e5a4f1e4f0ef3fa8/snapcraft_legacy/internal/repo/apt_cache.py#L120) with a try/except and providing a useful and actionable error message.
You can reproduce this with:
```bash
lxc launch ubuntu:22.04 repro-env
lxc exec repro-env bash
apt update
apt install aptdaemon -y # to install /etc/apt/apt.conf.d/20dbus
snap install snapcraft --classic
su ubuntu
cd ~
mkdir test-snap
cd test-snap
snapcraft init
sed -i 's/core22/core20/g' snap/snapcraft.yaml
echo " stage-packages: [curl]" >> snap/snapcraft.yaml
snapcraft --destructive-mode
snapcraft clean --destructive-mode
sudo --preserve-env=HOME snapcraft --destructive-mode # --preserve-env=HOME not needed in ubuntu<19.10
sudo --preserve-env=HOME snapcraft clean --destructive-mode
snapcraft --destructive-mode
```
Error:
```
Sorry, an error occurred in Snapcraft:
[Errno 13] Permission denied: 'auth.conf.d'
We would appreciate it if you anonymously reported this issue.
No other data than the traceback and the version of snapcraft in use will be sent.
```
### Why it needs to get done
If snapcraft is run in destructive mode with sudo then without sudo, the error message doesn't help the user figure out how to clean their cache.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Superseded by snapcraft 8.14, which now warns when running destructive mode as a non-root user. The related improvement was merged in canonical/craft-application#974, providing clearer guidance for cache permission issues. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed as superseded by a related improvement in snapcraft 8.14. The application now warns when running in destructive mode as a non-root user, preventing the apt cache permission error. Resolved via canonical/craft-application#974. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed and superseded. A related improvement was merged into snapcraft 8.14 via craft-application PR #974, which now warns when running destructive-mode as a non-root user, addressing the cache permission issue. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed. A related improvement in snapcraft 8.14 via craft-application PR #974 now warns users when running in destructive-mode as a non-root user, preventing the apt cache permission error and removing the need for manual cleanup. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed as superseded. Snapcraft 8.14 now warns when running in destructive mode as a non-root user, resolving the apt cache permission issue. Implemented via craft-application PR #974. |
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. | |
| #5113 warn if `snapcraft --destructive-mode` is run by non-root user | snapcraft | closed | Resolved by adding a non-root warning for snapcraft destructive mode upstream in craft-application. The implementation was merged via canonical/craft-application#974, fixing permission errors and clarifying requirements. |