fix: snapcraft init crash when snapcraft.yaml exists but is empty
Metadata
Current evaluation
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.
Suggested action: —
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 |
|---|---|---|---|---|
| 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. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for snapcraft init crash when snapcraft.yaml exists but is empty. Resolved NoneType parsing error and added unit tests. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #669 Add detection for an existing `.snapcraft.yaml` file before running `snapcraft init` | snapcraft | merged | Merged fix preventing snapcraft init from creating a duplicate snapcraft.yaml when .snapcraft.yaml exists. A unit test was added per reviewer request before merge. | |
| #4662 fix(test): do not create 2 snapcraft.yaml and confuse location | snapcraft | merged | Merged a test fix preventing duplicate snapcraft.yaml creation in conflicting root and snap directories. Resolves silent overrides and ensures hooks are detected by clarifying fixture paths. Approved and merged. | |
| #2411 cli: snapcraft init with a base | snapcraft | merged | Merged. Adds a syntax documentation link after snapcraft init execution. Approved by one reviewer, passed CI checks, modified five files, and achieved 100% diff coverage. Resolves LP #1803776. | |
| #582 Support for a hidden snapcraft.yaml | snapcraft | merged | Merged. Adds support for a hidden .snapcraft.yaml config, erroring if both it and snapcraft.yaml exist. snapcraft init still creates the standard file. Incorporated reviewer terminology feedback and passed retests before merging. | |
| #725 Support having the snapcraft.yaml in a subdir. | snapcraft | merged | Merged a fix for a recursion crash when snapcraft.yaml resides in a project subdirectory. The change skips the config directory during processing, resolving Launchpad bug #1600428. Modified 7 files with 85 additions and 4 deletions. | |
| #1660880 snapcraft init doesn't finish the yaml with an empty line | snapcraft (launchpad) | closed | Closed. The missing trailing newline in generated snapcraft.yaml was fixed. The update ensures generated files adhere to standard formatting conventions. | |
| #5004 ci: make snapcraft.yaml render as YAML in bug reports | snapcraft | merged | Merged a one-line CI update ensuring snapcraft.yaml renders as proper YAML in bug reports. Approved by two reviewers, passed all checks, and integrated into the codebase. | |
| #885 fix: Removed reference to snapcraft.yaml in expand extensions | rockcraft | open | One-line fix removing the snapcraft.yaml reference from the expand-extensions help text and docstring, fixing #658. Approved by 2 reviewers with all CI checks green, but unmerged and inactive ~6 months; the fix is still unapplied in the codebase. |