← Back to issue list

Snapcraft raises an internal error if there is a file called `snap`

View original Github issue

Metadata

Project
snapcraft
Number
#5167
Type
issue
State
closed
Author
mr-cal
Labels
good first issue Status: Triaged Type: Bug
Created
Updated
Closed

Current evaluation

Fixed by merged PR #5512 (commit 02e267fb9): get_snap_project now catches NotADirectoryError and raises ProjectDirectoryTypeError instead of crashing when a file named 'snap' exists in the project directory.

Resolution: closed resolved

Reason: Maintainer mr-cal closed the issue with 'Fixed via #5512'. PR #5512 (commit 02e267fb9, 'fix: don't crash if "snap" is a file') was merged and adds a NotADirectoryError handler in snapcraft/parts/yaml_utils.py raising craft_application.errors.ProjectDirectoryTypeError with the resolution 'Rename or remove the file named snap', plus a unit test.

Evaluated by: mr-cal-bot

No scores available.

Issue body

### Bug Description Running a snapcraft command fail if there is a file called snap in the pwd. ### To Reproduce `touch snap` `snapcraft login` ### Environment Snapcraft 8.6.0 ### snapcraft.yaml ```yaml n/a ``` ### Relevant log output ```shell phelps@arch ~/f/tmp> ls phelps@arch ~/f/tmp> touch snap phelps@arch ~/f/tmp> snapcraft login Traceback (most recent call last): File "/snap/snapcraft/13008/bin/snapcraft", line 8, in <module> sys.exit(main()) File "/var/lib/snapd/snap/snapcraft/13008/lib/python3.10/site-packages/snapcraft/application.py", line 479, in main app = create_app() File "/var/lib/snapd/snap/snapcraft/13008/lib/python3.10/site-packages/snapcraft/application.py", line 455, in create_app app = Snapcraft( File "/var/lib/snapd/snap/snapcraft/13008/lib/python3.10/site-packages/snapcraft/application.py", line 104, in __init__ self._snapcraft_yaml_path: pathlib.Path | None = self._resolve_project_path( File "/var/lib/snapd/snap/snapcraft/13008/lib/python3.10/site-packages/snapcraft/application.py", line 160, in _resolve_project_path return super()._resolve_project_path(project_dir / "snap") File "/var/lib/snapd/snap/snapcraft/13008/lib/python3.10/site-packages/craft_application/application.py", line 325, in _resolve_project_path return (project_dir / f"{self.app.name}.yaml").resolve(strict=True) File "/var/lib/snapd/snap/snapcraft/13008/usr/lib/python3.10/pathlib.py", line 1077, in resolve s = self._accessor.realpath(self, strict=strict) File "/var/lib/snapd/snap/snapcraft/13008/bin/../usr/lib/python3.10/posixpath.py", line 396, in realpath path, ok = _joinrealpath(filename[:0], filename, strict, {}) File "/var/lib/snapd/snap/snapcraft/13008/bin/../usr/lib/python3.10/posixpath.py", line 431, in _joinrealpath st = os.lstat(newpath) NotADirectoryError: [Errno 20] Not a directory: '/home/phelps/files/tmp/snap/snapcraft.yaml' phelps@arch ~/f/tmp [1]> rm snap phelps@arch ~/f/tmp> snapcraft login Enter your Ubuntu One e-mail address and password. If you do not have an Ubuntu One account, you can create one at https://snapcraft.io/account ``` ### Additional context _No response_

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #5512 (commit 02e267fb9): get_snap_project now catches NotADirectoryError and raises ProjectDirectoryTypeError instead of crashing when a file named 'snap' exists in the project directory.
stealth/space-bunny-alpha — closed resolved Snapcraft now reports a clear error when ./snap is a file instead of crashing. Merged PR #5512 (commit 02e267fb9) resolved #5167.
qwen/qwen3.6-35b-a3b — — Snapcraft crashed with a NotADirectoryError when a file named snap existed in the working directory. The bug was fixed via pull request #5512 and the issue is closed.
qwen/qwen3.6-35b-a3b — — Resolved a NotADirectoryError crash when a file named snap existed in the working directory. Fixed via pull request #5512.
qwen3.6-35b-a3b-mtp-q6 — — Fixed a NotADirectoryError crash triggered by a file named snap in the working directory. Resolved via pull request #5512.

Update history

No update history recorded yet.

Related work

  • Likely Fixed By: snapcraft#5512 (confidence 99%)

    Merged PR that added the NotADirectoryError handling in get_snap_project; commit 02e267fb9.

Related issues

Issue Project State Summary Similarity
#5512 fix: don't crash if "snap" is a file snapcraft merged PR #5512 (commit 02e267fb9) merged: snapcraft now raises ProjectDirectoryTypeError with a clear message when ./snap is a file instead of crashing, fixing issue #5167.
83%
#1717413 snapcraft snap with an unexisting dir shows a traceback snapcraft (launchpad) closed Missing-directory handling was fixed to return a clear SnapcraftEnvironmentError instead of a traceback; Launchpad bug #1717413 is closed as Fixed.
75%
#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.
70%
#21 snapcraft throws FileExistsError: with very simple Python snap snapcraft closed Replaced the FileExistsError with local-source validation in 0e575ce53; corrected local-source handling merged via PR #377 (8b4a18d9b).
70%
#1720230 snapcraft fails in a directory with spaces snapcraft (launchpad) closed Fixed directory names with spaces by quoting environment-variable values in project_loader; merged as snapcore/snapcraft#1578 (commit d154224d7).
70%