Skip to content

libflake: add lock file path to invalid json error#12936

Merged
mergify[bot] merged 1 commit intomasterfrom
unknown repository
Apr 6, 2025
Merged

libflake: add lock file path to invalid json error#12936
mergify[bot] merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Apr 6, 2025

Motivation

Previously, when lock file contained invalid JSON nix reported a parser
error without specifying the file it came from. This behavior is confusing.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@ghost ghost requested a review from edolstra as a code owner April 6, 2025 10:53
Comment thread src/libflake/flake/lockfile.cc Outdated
try {
return nlohmann::json::parse(contents);
} catch (const nlohmann::json::parse_error & e) {
throw Error("While parsing '%s': %s", path, e.what());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had in mind an addTrace context when I put "while parsing" in the issue, but I think making it part of the final message is nicer, so let's make it sound a bit more natural:

Suggested change
throw Error("While parsing '%s': %s", path, e.what());
throw Error("Could not parse '%s': %s", path, e.what());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks! Updated.

@roberth roberth added the backport 2.28-maintenance Automatically creates a PR against the branch label Apr 6, 2025
Previously, when lock file contained invalid JSON nix reported a parser
error without specifying the file it came from.

This change adds flake.lock file path to the error message to avoid
confusion.
Copy link
Copy Markdown
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@roberth
Copy link
Copy Markdown
Member

roberth commented Apr 6, 2025

@mergify queue

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 6, 2025

queue

✅ The pull request has been merged automatically

Details

The pull request has been merged automatically at 1dc7e6c

mergify Bot added a commit that referenced this pull request Apr 6, 2025
@mergify mergify Bot merged commit 1dc7e6c into NixOS:master Apr 6, 2025
13 checks passed
edolstra added a commit that referenced this pull request Apr 7, 2025
…2936

libflake: add lock file path to invalid json error (backport #12936)
@jeremyschlatter
Copy link
Copy Markdown
Contributor

This also fixed #6151.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.28-maintenance Automatically creates a PR against the branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge conflict in flake.lock produces bad error

3 participants