`--debug` does not enter a shell for failures during post-prime or packing
Metadata
Current evaluation
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.
Suggested action: —
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 |
|---|---|---|---|---|
| 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. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Fixed in snapcraft 8.4.1. The debug flag failed to drop into a shell during post-prime or packing failures for core24 snaps due to a craft-application regression. Resolved via craft-application PR 436 and released in snapcraft 8.4.1. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #415 `--debug` does not enter a shell for failures during post-prime or packing | craft-application | closed | Resolved in pull request #436. The --debug flag now correctly opens a shell when post-prime or packing steps fail, fixing a regression that blocked artifact troubleshooting. | |
| #1074 --shell and --debug fail cryptically with late pack failures | craft-application | closed | Closed and transferred to craft-application repository. Root cause identified: post-prime failures bypass --shell/--debug guards. Fix requires wrapping _run_post_prime_steps() in error handling. Pending upstream resolution. |