← 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

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.

Suggested action:

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
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.
qwen3.6-35b-a3b-mtp-q6 Fixed a NotADirectoryError crash in snapcraft when a file named snap exists in the working directory. The bug was resolved via pull request #5512 by correcting the project path resolution logic to handle the conflicting filename.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#1717413 snapcraft snap with an unexisting dir shows a traceback snapcraft (launchpad) closed Fixed by implementing proper error handling for missing directories. The Python traceback was replaced with a clear SnapcraftEnvironmentError, providing users with a concise message to verify the directory path before running snapcraft.
76%
#21 snapcraft throws FileExistsError: with very simple Python snap snapcraft closed Fixed in a maintainer branch. The FileExistsError during snapcraft stage was resolved by replacing the traceback with a clear error message indicating that the local source path must be a directory.
74%
#2098999 Snapcraft auth does not create dir needed and errors out snapcraft (launchpad) open Snapcraft auth fails to create credentials directory on macOS, causing FileNotFoundError. Issue is 560 days old with no maintainer response.
72%
#1867052 Snapcraft crashes while creating snap for ssh-audit snapcraft (launchpad) closed Snapcraft v2.43.1 crashes with FileNotFoundError during snap packaging due to a missing executable path in snapcraft.yaml. Issue is completely inactive for over 6 years.
72%
#5512 fix: don't crash if "snap" is a file snapcraft merged Merged fix preventing crashes when the snap directory is replaced by a file. The change raises a ProjectDirectoryTypeError with improved error messaging, resolving issue #5167. Approved by two reviewers and passed CI checks.
71%
#1499424 snapcraft throws FileExistsError: with very simple Python snap snapcraft (launchpad) closed Closed without comments or explicit resolution. The FileExistsError during snapcraft stage was likely resolved in a subsequent snapcraft release or abandoned due to inactivity.
71%
#1497371 snapcraft clean fails on a clean directory snapcraft (launchpad) closed Fixed a FileNotFoundError crash in snapcraft clean when executed on a fresh directory. The command now gracefully handles the absence of the parts directory instead of failing.
70%