← Back to issue list

Error messages when running scriplets make debugging failures difficult

View original Github issue

Metadata

Project
snapcraft
Number
#4372
Type
issue
State
closed
Author
dilyn-corner
Labels
—
Created
Updated
Closed

Current evaluation

Scriptlet failures reported unrelated line numbers and untransformed errors. Fixed via craft-parts#966 (49cde073) and #897 (5bbd983e), shipped in Snapcraft 8.6; author confirmed closure in Feb 2025.

Resolution: closed resolved

Reason: Maintainer bepri closed the issue pointing to craft-parts PR #966 (commit 49cde073, capturing scriptlet errors as ScriptletRunError) and PR #897 (commit 5bbd983e, splitting stderr for better error presentation), both of which landed in Snapcraft 8.6. Reporter dilyn-corner agreed the work resolved it.

Evaluated by: mr-cal-bot

No scores available.

Issue body

### Bug Description When a part in some snap's `snapcraft.yaml` includes a scriplet, error messages surrounding failures of that scriplet are "incorrect" in that they do not correspond to problems within the YAML file itself, but instead in some ancillary file which (I presume) `snapcraft` is creating and then executing during the parts lifecycle event. This means that debugging any given scriplet failure is never deterministically difficult; instead, the difficulty of determining what failed, where it failed, and why it failed can range from 'trivial' (the context surrounding the error easily disambiguates the failure) to 'impossible' (the error message is a nonsequitor, the surrounding context isn't why it failed but instead some earlier part which failed, etc.). In short: instead of debugging the scriplet in my `snapcraft.yaml` which is, for all intents and purposes, a shell script, I have to debug the transformation of my scriplet into some nonobvious, unavailable-by-default, created-by-snapcraft script. ### To Reproduce Reproducing the issue is straightforward. The YAML posted below will produce an error of the relevant kind. To replicate my environment: `snap refresh --channel=7.x/stable snapcraft` `snapcraft --use-lxd` ### Environment Some variant of Ubuntu 23.04 with `snapcraft` from 7.x/stable, revision 9542. Build the example snap with `snapcraft --use-lxd`. ### snapcraft.yaml ```shell 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 override-build: | cat >> test.sh << EOF #!/bin/sh -eux foo=bar bar=$baz EOF ``` ### Relevant log output ```shell Starting Snapcraft 7.5.2 Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20230921-105432.570321.log' Running on amd64 for amd64 Cleaning build provider Cleaned build provider Starting Snapcraft 7.5.2 Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20230921-105434.907064.log' Running on amd64 for amd64 Launching instance... Checking for instance 'snapcraft-my-snap-name-on-amd64-for-amd64-2193722' in project 'snapcraft' in remote 'local' Instance 'snapcraft-my-snap-name-on-amd64-for-amd64-2193722' does not exist. Checking for base instance 'base-instance-snapcraft-buildd-base-v10--2d55678e0339df02cd48' in project 'snapcraft' in remote 'local' Creating instance from base instance 'base-instance-snapcraft-buildd-base-v10--2d55678e0339df02cd48' Starting instance. Starting Snapcraft 7.5.2 Logging execution to '/tmp/snapcraft.log' Running on amd64 for amd64 Initializing parts lifecycle Executing parts lifecycle... Executing parts lifecycle: pull my-part Executing action Executed: pull my-part Executing parts lifecycle: build my-part Executing action :: + cat :: /bin/bash: line 41: baz: unbound variable 'override-build' in part 'my-part' failed with code 1. Review the scriptlet and make sure it's correct. Failed to execute pack in instance. Full execution log: '/home/dilyn/.local/state/snapcraft/log/snapcraft-20230921-105434.907064.log' ``` ### Additional context Ideally, the error message will at least indicate which line of the YAML is causing the failure. I have no idea how tricky this reverse-engineering would be in practice. An alternative would be to increase the visibility on build failures to the host machine. Perhaps by including the transformed scriplet which is being executed in the build environment for that part in the generated log file?

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Scriptlet failures reported unrelated line numbers and untransformed errors. Fixed via craft-parts#966 (49cde073) and #897 (5bbd983e), shipped in Snapcraft 8.6; author confirmed closure in Feb 2025.
stealth/space-bunny-alpha — closed resolved Fixed by craft-parts PRs #897 and #966, which improved scriptlet error reporting and shipped in Snapcraft 8.6.
qwen/qwen3.6-35b-a3b — — Resolved via craft-parts PRs #966 and #897, included in Snapcraft 8.6. Error reporting now accurately traces scriplet failures to the original YAML, replacing confusing generated script tracebacks with clear, actionable messages.
qwen/qwen3.6-35b-a3b — — Fixed. Improved scriplet error reporting was implemented in craft-parts PRs #966 and #897, resolving the confusing failure messages. The fix was released in Snapcraft 8.6.
qwen/qwen3.6-35b-a3b — — Fixed via craft-parts PRs #966 and #897, released in Snapcraft 8.6. Error reporting now accurately points to the failing scriplet line in the original YAML, resolving the debugging difficulty.
qwen3.6-35b-a3b-mtp-q6 — — Fixed via craft-parts PRs #966 and #897, released in Snapcraft 8.6. Scriplet error messages now accurately reference the original script lines, resolving debugging difficulties.

Update history

No update history recorded yet.

Related work

  • Likely Fixed By: canonical/craft-parts#966 (confidence 95%)

    Merged PR that replaced named pipes with Unix sockets so scriptlet errors are captured and surfaced properly

  • Likely Fixed By: canonical/craft-parts#897 (confidence 93%)

    Merged PR splitting stderr for better error presentation of scriptlet output

Related issues

Issue Project State Summary Similarity
#1466 scriptlets erroring behavior snapcraft closed Fixed in snapcraft#1545 (commit 3a18cc87a): scriptlets now fail on any command error, not only the final command.
73%
#5203 feat(parts): capture error message from scriptlets snapcraft closed Closed unmerged; commit 1b44db714 later made the equivalent Craft Parts 2.1.0 bump, delivering scriptlet stderr capture through canonical/craft-parts#897.
71%