snapcraft
snapcraft copied to clipboard
Make `snap pack ...` errors also return the problem instead of just the error code
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 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'