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

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

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

ajlekcahdp4
Copy link
Contributor

@ajlekcahdp4 ajlekcahdp4 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.

@ajlekcahdp4 ajlekcahdp4 requested a review from edolstra as a code owner April 6, 2025 10:53
try {
return nlohmann::json::parse(contents);
} catch (const nlohmann::json::parse_error & e) {
throw Error("While parsing '%s': %s", path, e.what());
Copy link
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
Contributor 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
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
Member

roberth commented Apr 6, 2025

@mergify queue

Copy link
Contributor

mergify bot commented Apr 6, 2025

queue

✅ The pull request has been merged automatically

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)
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
2 participants