`--debug` does not enter a shell for failures during post-prime or packing
Metadata
Current evaluation
Fixed in Snapcraft 8.4.1: core24 --debug now opens a shell after post-prime or packing failures via craft-application PR #436 (ab55ec81).
Resolution: closed resolved
Reason: The lifecycle behavior was corrected upstream in canonical/craft-application#436 at commit ab55ec81. A maintainer confirmed the fix shipped in Snapcraft 8.4.1.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
I'm building a snap locally using `--use-lxd` and it sometimes fails to build. I would expect `--debug` to allow me to drop into the container to debug the process.
Unfortunately, it only sometimes does this, and sometimes doesn't allow me to.
The `--debug` option appears to be limited to specific stages of `snapcraft`, when my expectation is at any time I should be able to jump into the container with `--debug` and figure out (debug) the problem.
Running `snapcraft --debug --use-lxd` and being left at the host terminal, means I have to jump through other hoops to identify the problem with the build. It shouldn't be this hard.
### To Reproduce
Build a snap which has a missing binary, that is the `apps` stanza points to a `command` that doesn't exist. Run `snapcraft --use-lxd --debug` and the build will fail, but you will not be dropped into the container to debug it.
### Environment
Ubuntu 24.04 building a core24 snap using lxd latest from stable, and snapcraft from stable.
### snapcraft.yaml
```shell
name: grype
base: core24
version: "v0.79.6"
summary: Vulnerability scanner
description: |
CLI vulnerability scanner for container images and filesystems
platforms:
amd64:
build-on: [amd64]
build-for: [amd64]
arm64:
build-on: [arm64]
build-for: [arm64]
# armhf:
# build-on: [armhf]
# build-for: [armhf]
s390x:
build-for: [s390x]
build-on: [s390x]
ppc64el:
build-for: [ppc64el]
build-on: [ppc64el]
# riscv64:
# build-on: [riscv64]
# build-for: [riscv64]
grade: stable
confinement: classic
parts:
grype:
plugin: nil
source: https://github.com/anchore/${SNAPCRAFT_PROJECT_NAME}/releases/download/v${SNAPCRAFT_PROJECT_VERSION}/${SNAPCRAFT_PROJECT_NAME}_${SNAPCRAFT_PROJECT_VERSION}_linux_${CRAFT_ARCH_BUILD_FOR}.tar.gz
override-pull: |
upstream_arch="$CRAFT_ARCH_BUILD_FOR"
# Go releaser uses a different nomenclature for architecture on ppc64
if [ "$CRAFT_ARCH_BUILD_FOR" == "ppc64el" ]; then
upstream_arch="ppc64le"
fi
ver_no_v=$(echo $SNAPCRAFT_PROJECT_VERSION | tr -d "v")
wget -O grype.tar.gz https://github.com/anchore/${SNAPCRAFT_PROJECT_NAME}/releases/download/${SNAPCRAFT_PROJECT_VERSION}/${SNAPCRAFT_PROJECT_NAME}_${ver_no_v}_linux_${upstream_arch}.tar.gz
tar zxvf grype.tar.gz
#mkdir "$SNAPCRAFT_PART_INSTALL"/bin
install LICENSE "$SNAPCRAFT_PART_INSTALL"
install README.md "$SNAPCRAFT_PART_INSTALL"
install CHANGELOG.md "$SNAPCRAFT_PART_INSTALL"
install grype "$SNAPCRAFT_PART_INSTALL"/bin
build-packages:
- wget
apps:
grype:
command: bin/grype
```
### Relevant log output
```shell
cat snapcraft --use-lxd --verbose --debug
Starting snapcraft, version 8.3.2
Logging execution to '/home/alan/.local/state/snapcraft/log/snapcraft-20240812-205228.881332.log'
Launching managed ubuntu 24.04 instance...
Starting instance
Starting snapcraft, version 8.3.2
Logging execution to '/tmp/snapcraft.log'
Starting snapcraft, version 8.3.2
Logging execution to '/tmp/snapcraft.log'
Initialising lifecycle
Installing build-packages
Installing build-snaps
Skipping pull for grype (already ran)
Skipping build for grype (already ran)
Skipping stage for grype (already ran)
Skipping prime for grype (already ran)
Packing...
Reading snap metadata...
Running linters...
Running linter: classic
Running linter: library
Lint OK:
- classic: Snap confinement is set to classic.
Creating snap package...
Command '['snap', 'pack', '--filename', 'grype_v0.79.6_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
Failed to execute snapcraft in instance.
Full execution log: '/home/alan/.local/state/snapcraft/log/snapcraft-20240812-205228.881332.log'
```
### Additional context
Remove the comment from the mkdir command to 'fix' the above yaml.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Fixed in Snapcraft 8.4.1: core24 --debug now opens a shell after post-prime or packing failures via craft-application PR #436 (ab55ec81). | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed in Snapcraft 8.4.1: core24 --debug now opens a shell for post-prime and packing failures, via craft-application PR #436 (ab55ec81). | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed via canonical/craft-application#436 (commit ab55ec81); --debug now opens a shell after post-prime or packing failures, released in snapcraft 8.4.1. | |
| qwen/qwen3.6-35b-a3b | — | — | The --debug flag failed to enter a container during post-prime or packing failures for core24 snaps due to a craft-application regression. Fixed via craft-application PR #436 and released in snapcraft 8.4.1. | |
| qwen/qwen3.6-35b-a3b | — | — | The --debug flag failed to drop into a shell during post-prime or packing stages for core24 snaps due to a craft-application regression. Fixed via craft-application PR 436 and released in snapcraft 8.4.1. | |
| qwen/qwen3.6-35b-a3b | — | — | Fixed a regression where --debug failed to drop into a container during post-prime and packing stages. Resolved via craft-application PR #436 and included in snapcraft 8.4.1. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Fixed in snapcraft 8.4.1. The --debug flag now correctly drops into a shell for failures during post-prime and packing stages for core24 snaps. Resolution implemented via craft-application PR 436. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/craft-application#436
(confidence 100%)
Upstream fix for entering a debug shell when post-prime or packing fails.
-
Related To:
canonical/craft-application#415
(confidence 98%)
Upstream issue tracking the core24 lifecycle regression.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #415 `--debug` does not enter a shell for failures during post-prime or packing | craft-application | closed | Fixed by merged PR #436 (commit ab55ec81), adding --shell/--shell-after to pack and making --debug drop into a shell when packing fails; closed by maintainer tigarmo on 2024-09-10. | |
| #1073 fix: handle `--debug` for post-prime failures | craft-application | merged | Merged PR #1073 (commit 38fdb686) preserves --debug shell handling when post-prime actions such as Snapcraft pack fail, fixing #1074. | |
| #1074 --shell and --debug fail cryptically with late pack failures | craft-application | closed | Fixed in merged PR #1073 (commit 38fdb686), which added post-prime failure handling so --debug can open a shell instead of only reporting an instance error. | |
| #436 feat: support shell/shell-after and debug in 'pack' | craft-application | merged | Merged craft-application#436 (commit ab55ec81), adding --shell/--shell-after to pack and making --debug shell into the build environment when packing fails; fixes #430. | |
| #1848513 --debug does not expose appropriate environment variables | snapcraft (launchpad) | open | The `--debug` failure shell launches bare bash without the failed action's Snapcraft or part environment, preventing faithful command reproduction. The old report remains unlabelled and untriaged. | |
| #1609803 snapcraft cleanbuild --no-clean-up | snapcraft (launchpad) | closed | Cleanbuild debugging landed in snapcore/snapcraft PR #740 (commit a24083e75); follow-up PR #1404 made --debug enter a shell when builds fail. | |
| #1782773 Add --debug for lifecycle steps | snapcraft (launchpad) | closed | Merged snapcraft#3718 (e2ff471b9) added --debug to open a shell in the part build environment after lifecycle errors. | |
| #1782770 Add --debug for lifecycle steps | snapcraft (launchpad) | closed | Closed as stale after no activity. Debug-shell support was later implemented in canonical/snapcraft#2252 (commit 3410ec32d). |