fix: snapcraft init crash when snapcraft.yaml exists but is empty
Metadata
Current evaluation
Merged #5664 as commit f78e6e5d1, preventing snapcraft init from crashing when snapcraft.yaml is empty or invalid and adding unit coverage.
Resolution: closed resolved
Reason: PR canonical/snapcraft#5664 was approved and merged. Commit f78e6e5d1 adds a non-dictionary YAML guard that safely falls back when snapcraft.yaml is empty or invalid.
Evaluated by: mr-cal-bot
No scores available.
Issue body
- [ ] Have you followed the [guidelines for contributing](https://github.com/canonical/snapcraft/blob/main/CONTRIBUTING.md)?
- [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [ ] Have you successfully run `make lint`?
- [ ] Have you successfully run `make test`?
---
Fixes the crash when running `snapcraft init` in a directory with an empty `snapcraft.yaml`:
```
$ cd `mktemp -d`
$ touch snapcraft.yaml
$ snapcraft init
Traceback (most recent call last):
File "/snap/snapcraft/15369/bin/snapcraft", line 8, in <module>
sys.exit(main())
^^^^^^
File "/snap/snapcraft/15369/lib/python3.12/site-packages/snapcraft/application.py", line 464, in main
app = create_app()
^^^^^^^^^^^^
File "/snap/snapcraft/15369/lib/python3.12/site-packages/snapcraft/application.py", line 432, in create_app
app = Snapcraft(
^^^^^^^^^^
File "/snap/snapcraft/15369/lib/python3.12/site-packages/snapcraft/application.py", line 99, in __init__
self._known_core24 = self._get_known_core24()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/snap/snapcraft/15369/lib/python3.12/site-packages/snapcraft/application.py", line 118, in _get_known_core24
base = _snapcraft_yaml_data.get("base")
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged #5664 as commit f78e6e5d1, preventing snapcraft init from crashing when snapcraft.yaml is empty or invalid and adding unit coverage. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged in canonical/snapcraft#5664: prevent snapcraft init from crashing when an existing empty snapcraft.yaml loads as None, with added unit coverage. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged a fix for a snapcraft init crash when snapcraft.yaml exists but is empty. The PR addressed review comments, added unit tests, and passed all CI checks before merging. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for snapcraft init crash when an empty snapcraft.yaml exists. Added null handling for missing YAML data and a regression test. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1604326 snapcraft init doesn't fail if there is a .snapcraft.yaml file | snapcraft (launchpad) | closed | Fixed by merged snapcraft#669 (commit 2cd727259): snapcraft init now detects an existing .snapcraft.yaml and fails instead of creating snapcraft.yaml. | |
| #669 Add detection for an existing `.snapcraft.yaml` file before running `snapcraft init` | snapcraft | merged | Merged PR #669 (commit 2cd727259) makes snapcraft init detect an existing .snapcraft.yaml, preventing creation of a duplicate snapcraft.yaml; a unit test was added. |