← Back to issue list

fix: warn when part sources resolve from the parent of a snap directory

View original Github issue

Metadata

Project
snapcraft
Number
#6502
Type
pull request
State
open
Author
LoweRAM
Labels
—
Created
Updated
Closed
—

Current evaluation

Adds a warning when snapcraft is run from inside a snap/ directory and part sources resolve from the parent directory, fixing confusing error messages. All CI passing, awaiting review.

Suggested action: needs review

Reason: The PR is 4 days old with all CI checks passing, 0 review comments, and addresses issue #6501 by adding a helpful warning for users running snapcraft from the wrong directory. It's ready for maintainer review with a clean diff (+247/-2 lines, 3 files) and comprehensive unit tests covering positive and negative cases.

Evaluated by: mr-cal-bot

Impact: 45 Quick Win: 23 Complexity: 35 Confidence: 75 Actionability: 80

Issue body

A project may keep its `snapcraft.yaml` inside a `snap/` subdirectory while writing part sources relative to the repository root. `source` paths resolve against the directory snapcraft is invoked from, not the location of the project file, so packing from inside `snap/` resolves them against the wrong directory: ``` $ cd snap $ snapcraft pack --use-lxd Failed to pull source: unable to determine source type of 'snap/local'. ``` Nothing is wrong with the source type — `snap/local` exists and is a valid local source. The error names the wrong problem, so the reader goes looking for a `source-type` mistake that does not exist, and the build fails before it can say which path it searched. This warning fires when all three conditions hold: - the project directory is named `snap` - the project file sits directly in it, rather than a nested layout such as `build-aux/snap/snapcraft.yaml` - a part source exists in the parent directory but not in the project directory The third condition is what keeps it quiet when there is no evidence. URLs and absolute paths resolve identically from both directories, so they never qualify and the check does not need to reimplement craft-parts' source type detection. In managed mode the warning is emitted on the host before the build instance is launched. Fixes #6501. ## Verification Reproduced against a project shaped like `juju/juju` (branch `3.6`), which is where the report came from. Packing from `snap/` warns and then fails as before; packing from the repository root produces the snap with no warning. ``` $ cd snap && snapcraft pack --use-lxd Warning: Part source 'snap/local' does not exist relative to '/…/snap', but does exist relative to its parent. Snapcraft may be running from the wrong directory - try running it from '/…/juju' instead. ... Failed to pull source: unable to determine source type of 'snap/local'. $ cd .. && snapcraft pack --use-lxd ... Packed warnrepro_1.0_amd64.snap ``` `make lint-code` and `make test-fast` pass. Unit tests cover the warning firing, one-shot behaviour, multiple unresolved sources, and the negative cases for remote sources, sources that resolve in place, non-`snap` directories, nested project files, and parts without a plain local source. ## Known limits - Grammar-shaped sources (`source: {on amd64: …}`) are not inspected, since parts grammar is processed after this check runs. There is a test pinning that behaviour; widen it if it proves to matter. - This is a warning only. The misleading message from craft-parts is untouched — improving it would be a change in `craft-parts`, which benefits every craft app rather than just snapcraft. --- - [x] I've followed the [contribution guidelines](https://github.com/canonical/snapcraft/blob/main/CONTRIBUTING.md). - [x] I've signed the [CLA](http://www.ubuntu.com/legal/contributors/). - [x] I've successfully run `make lint && make test`. - [x] I've added or updated any relevant documentation. - [ ] In documents I changed, I [added a meta description](https://canonical-starflow.readthedocs-hosted.com/how-to/add-a-page-meta-description/) if one was missing. - [x] I've updated the relevant release notes.

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b
Impact: 45
Quick Win: 23
Complexity: 35
Confidence: 75
Actionability: 80
needs review Adds a warning when snapcraft is run from inside a snap/ directory and part sources resolve from the parent directory, fixing confusing error messages. All CI passing, awaiting review.

Update history

Date Change
updated
created

Related issues

Issue Project State Summary Similarity
#3379 cli: warn when running snapcraft inside assets directory snapcraft merged Merged #3379 (commit 54162eb95), adding a CLI warning when Snapcraft runs from snap or build-aux asset directories.
72%