Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flakes: bare minimum fix the error message for untracked flake.nix #9398

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

Qyriad
Copy link
Member

@Qyriad Qyriad commented Nov 20, 2023

tl;dr

Before:

warning: Git tree '/home/qyriad/code/new-repo' is dirty
error: getting status of '/nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source/flake.nix': No such file or directory

After:

warning: Git tree '/home/qyriad/code/new-repo' is dirty
error: source tree referenced by 'git+file:///home/qyriad/code/new-repo' does not contain a '/flake.nix' file

Motivation

error: getting status of /nix/store/path/flake.nix: No such file or directory is an extremely confusing error message, with multiple related open issues (#6642, #7107), Discourse threads, Reddit threads, and even blog posts about it.

This problem warrants far more helpful diagnostics than this PR adds, however the current UX is so poor and the fix so trivial I felt it warranted a separate, bare minimum PR before I work on more complex diagnostics.

Context

Since canonPath(resolveSymlinks = true) calls lstat() on its argument, I'm pretty sure it's impossible for a pathExists() check after it to return false. Because of that I moved the check entirely to before the canonPath() calls, instead of duplicating them.

Priorities

Add 👍 to pull requests you find important.

getFlake currently calls lstat (via isLink via canonPath) before it
performs the sanity check that a flake.nix exists in the first place.
This commit moves the check to before path canonicalization, so that
failed symlink check operations don't throw before the check does.
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

That is indeed only a marginal improvement, but still a certain one!

@thufschmitt thufschmitt merged commit 7f626db into NixOS:master Nov 24, 2023
8 checks passed
@fricklerhandwerk fricklerhandwerk added the error-messages Confusing messages and better diagnostics label Jan 8, 2024
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
flakes: bare minimum fix the error message for untracked flake.nix
(cherry picked from commit 7f626db)
Change-Id: I470ac56a670a8c11e4164c6b059184a02344d491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messages Confusing messages and better diagnostics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants