Make `snap pack ...` errors also return the problem instead of just the error code
Metadata
Current evaluation
Closed by mr-cal as a duplicate of #4499 (tracked as CRAFT-2559); that issue was fixed by merged PR #5188 (commit a9fc44093), which surfaces snapd's error output when `snap pack` fails.
Resolution: closed superseded
Reason: Maintainer mr-cal closed this on 2024-07-22 as a duplicate of snapcraft#4499, where the fix landed via merged PR #5188 (commit a9fc44093) once snapd 2.66 added stderr support for `snap pack` failures.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### What needs to get done
If a `snap pack ...` invocation fails when building a snap with `snapcraft --verbosity={quiet,brief,verbose}`, the *cause* of the nonzero exit code should also be printed in addition to the failing command.
At the very least, the cause should be returned when using `--verbosity=verbose`.
### Why it needs to get done
(Using snapcraft revision 10458)
Take the below `snapcraft.yaml`:
```
name: my-snap-name # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
This is my-snap's description. You have a paragraph or two to tell the
most important story about your snap. Keep it under 100 words though,
we live in tweetspace and your description wants to look good in the snap
store.
grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
parts:
my-part:
# See 'snapcraft plugins'
plugin: nil
apps:
my-app:
command: bin/foobarbaz
```
when built with `snapcraft --verbosity={quiet,brief,verbose}`, some [error messages](###Error-messages) occur.
If you inspect the logs, it becomes quite obvious what the problem is:
```
2024-01-26 15:00:02.052 :: 2024-01-26 15:00:01.572 Pack command: ['snap', 'pack', '--filename', 'my-snap-name_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]
2024-01-26 15:00:02.052 :: 2024-01-26 15:00:01.590 Command '['snap', 'pack', '--filename', 'my-snap-name_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
2024-01-26 15:00:02.052 :: 2024-01-26 15:00:01.590 Detailed information: 2024/01/26 15:00:01.588710 container.go:215: in snap "my-snap-name": path "bin/foobarbaz" does not exist
2024-01-26 15:00:02.052 :: 2024/01/26 15:00:01.588767 container.go:215: in snap "my-snap-name": path "bin" does not exist
2024-01-26 15:00:02.052 :: error: cannot pack "/root/prime": snap is unusable due to missing files
```
This message shows up when using `--verbosity={debug,trace}`, but it would be more helpful if the cause of the nonzero exit were also printed in addition to the failing command.
### Error messages
```
dilyn@Ares:~/testing -> snapcraft --verbosity=quiet
Starting Snapcraft 8.0.2.post12+gitd75fdaf1
Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240126-145922.134478.log'
Command '['snap', 'pack', '--filename', 'my-snap-name_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
Failed to execute pack in instance.
Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
Full execution log: '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240126-145922.134478.log'
```
```
dilyn@Ares:~/testing -> snapcraft --verbosity=brief
Starting Snapcraft 8.0.2.post12+gitd75fdaf1
Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240126-145936.992467.log'
{snip for brevity}
Command '['snap', 'pack', '--filename', 'my-snap-name_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
Failed to execute pack in instance.
Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
Full execution log: '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240126-145936.992467.log'
```
```
dilyn@Ares:~/testing -> snapcraft --verbosity=verbose
Starting Snapcraft 8.0.2.post12+gitd75fdaf1
Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240126-145952.331874.log'
{snip for brevity}
Creating snap package...
Command '['snap', 'pack', '--filename', 'my-snap-name_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
Failed to execute pack in instance.
Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
Full execution log: '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240126-145952.331874.log'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed superseded | Closed by mr-cal as a duplicate of #4499 (tracked as CRAFT-2559); that issue was fixed by merged PR #5188 (commit a9fc44093), which surfaces snapd's error output when `snap pack` fails. | |
| stealth/space-bunny-alpha | — | closed superseded | Closed as a duplicate of snapcraft#4499. Pack-failure details were later exposed after snapd 2.66; PR #5188 (a9fc44093) improved the error message. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed as a duplicate. Error details from snap pack failures were lost during propagation from the managed instance to the outer process. The resolution is tracked in issue #4499. | |
| qwen/qwen3.6-35b-a3b | — | — | snapcraft pack hides error causes, showing only exit codes. Developers traced this to failed error propagation from the inner managed instance. It was closed as a duplicate of #4499, which tracks the fix. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed as a duplicate. The snap pack error propagation issue is superseded by issue #4499, which tracks implementing proper exception handling in craft-application to surface detailed error messages instead of generic exit codes. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed as a duplicate of issue #4499. The underlying error propagation bug between managed and outer snapcraft instances is tracked there. Detailed pack failure messages will be surfaced once that work is implemented. |
Update history
No update history recorded yet.
Related work
-
Duplicate Of:
canonical/snapcraft#4499
(confidence 97%)
Explicitly named by mr-cal in the closing comment as the place for this bug
-
Superseded By:
canonical/snapcraft#5188
(confidence 90%)
Merged PR that fixed #4499 by surfacing snapd's error output on pack failure
-
Related To:
canonical/snapcraft#5188
(confidence 70%)
Commit a9fc44093 is the resolving change referenced by #4499
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #4870 snapcraft pack error obtuse on snapd errors | snapcraft | closed | Closed as a duplicate of #4548, which was tracked by #4499; hidden snapd pack diagnostics were fixed by merged PR #5188 (a9fc44093). | |
| #5188 fix: improve error message from snapd pack | snapcraft | merged | Merged PR #5188 in commit a9fc44093, improving snapd pack failures by surfacing snapd's error output and fixing snapcraft#4499. | |
| #4923 Increase verbosity of `snapcraft`'s missing files error | snapcraft | closed | Closed as a duplicate of #4499; suppressed `snap pack` errors were fixed by merged PR #5188 (commit a9fc44093), which surfaced snapd's stderr. | |
| #4499 Failures when running `snap pack` don't get sent to the user. | snapcraft | closed | Fixed by merged PR #5188 (commit a9fc44093), which surfaces snapd's error output when snap pack fails instead of showing only the command and exit status. | |
| #4413 Error message on snap pack is not nice | snapcraft | closed | Fixed by merged PR #4424 (commit ec09cc07b): pack failures now show concise snapd errors while command details remain in execution logs; backported to 7.x and 8.x. |