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

Make @nix json structured build log parsing warn instead of fail #11921

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

roberth
Copy link
Member

@roberth roberth commented Nov 20, 2024

Motivation

A build may log with @nix something without the intent to write Nix structured logs, resulting in an obscure error.
This makes it easy to understand and continues the build.

Example:

echo '@nix ]['
bad JSON log message from builder: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal
@nix ][

Context

Cherry-picked from https://gerrit.lix.systems/c/lix/+/2057
Author @lheckemann

Priorities and Process

Add 👍 to pull requests you find important.

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

@roberth roberth added bug derivation-build The process of building an individual derivation (see also sandbox label) labels Nov 20, 2024
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Nov 20, 2024
@roberth roberth added backport 2.24-maintenance Automatically creates a PR against the branch backport 2.25-maintenance Automatically creates a PR against the branch labels Nov 20, 2024
return true;
} catch (nlohmann::json::exception &e) {
warn(
"warning: Unable to handle a JSON message from the builder: %s",
Copy link
Member

Choose a reason for hiding this comment

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

Don't like how this makes assumptions about where this function is being used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Spot on. That also fixes a technically incorrect message, although it was probably never seen.
Now:

            if (handleJSONLogMessage(s, worker.act, worker.hook->activities, "the build hook", true))

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

+1 on the idea, just don't like the anti-modular way the warning is done.

@roberth
Copy link
Member Author

roberth commented Nov 21, 2024

Interestingly, the post-build-hook does not have @nix parsing logic, so that's what that's not in the diff.

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Great now!

@Mic92
Copy link
Member

Mic92 commented Nov 24, 2024

@roberth CI fails.

lheckemann and others added 3 commits November 24, 2024 23:52
Before this change, expressions like:

with import <nixpkgs> {};
runCommand "foo" {} ''
  echo '@nix {}' >&$NIX_LOG_FD
''

would result in Lix crashing, because accessing nonexistent fields of
a JSON object throws an exception.

Rather than handling each field individually, we just catch JSON
exceptions wholesale. Since these log messages are an unusual
circumstance, log a warning when this happens.

Fixes #544.

Change-Id: Idc2d8acf6e37046b3ec212f42e29269163dca893
(cherry picked from commit e55cd3beea710db727fd966f265a1b715b7285f3)
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-11-20-nix-team-meeting-minutes-196/56688/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.24-maintenance Automatically creates a PR against the branch backport 2.25-maintenance Automatically creates a PR against the branch bug derivation-build The process of building an individual derivation (see also sandbox label) with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants