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
libutil/logging: extend internal-json
logger to make it more machine-readable
#3847
Conversation
Is Json a better name, because it's in a Json format? |
In the (unreleased) Nix 2.4 the error-messages have been reformatted[1]. This patch aims to retain proper `.nix`-support in `ale`, but is only targeted for folks using an unstable Nix version. Please note that this currently depends on a pending PR[2] which adds support for minimal JSON error-outputs. [1] NixOS/nix#3590 [2] NixOS/nix#3847
Fair point. Can we agree on cc @edolstra WDYT? |
I don't really understand why we need another JSON output format when we already have one. What information can't you get from the existing format? |
@edolstra the current json format returns a fully detailed message containing code-lines etc. This is IMHO fairly hard to parse for editor-plugins where I only need the line-number, line-column and message (which is provided in single JSON-fields in my new logger). Also, we probably want to use the full-blown human-readable message in the Finally, the I see two options to take care of it:
I'm fine with either of those options, so feel free to decide which you prefer. |
cc @bburdette who also might be interested in reviewing this as they implemented the beautiful new error-messages. |
I think it's better to improve the existing JSON logger than to add another one. The whole point of the JSON logger was that it's the last logger we'll ever need, since it should provide all information in a format that other tools can easily process.
I don't think that should be the case. Having a log format that can change in arbitrary ways is not very useful. I think it's more that clients should be prepared to handle message types or fields being added or removed. (Conversely though, who says that the a new logger wouldn't be subject to change?)
No, the daemon should send structured error messages to the client. Currently errors from the daemon don't get formatted very well. For instance, the daemon doesn't know the terminal width of the client. And it's hard for the client to add context to an error received from the daemon.
I think this is the best approach. The code lines can probably be put in a separate JSON field which tools like IDEs can ignore. |
Well, first of all it was explicitly stated in the man-pages. Also, error-information is only provided in the
That's also perfectly fine for me. I'll update the PR later today, thanks for your feedback! |
minimal
log-format which aims to be easily machine-readableinternal-json
logger to make it more machine-readable
@edolstra updated accordingly %) |
In the (unreleased) Nix 2.4 the error-messages have been reformatted[1]. This patch aims to retain proper `.nix`-support in `ale`, but is only targeted for folks using an unstable Nix version. Please note that this currently depends on a pending PR[2] which adds support for minimal JSON error-outputs. [1] NixOS/nix#3590 [2] NixOS/nix#3847
Maybe take a look at what i wrote in #3841 ? I think this separation of rendering and data would also be good for machine-readable logging; currently we bake a lot of data in the hint which is conceptually separate, and should be actually separate for machine-readable logging. |
I like it! I could see adding the trace info into the json format if at some point there's a tool that needs it. |
@bburdette fair point, added traces as well. |
Yes I suppose this changes are independent of this PR. |
…e-readable The new error-format is pretty nice from a UX point-of-view, however it's fairly hard to parse the output e.g. for editor plugins such as vim-ale[1] that use `nix-instantiate --parse` to determine syntax errors in Nix expression files. This patch extends the `internal-json` logger by adding the fields `line`, `column` and `file` to easily locate an error in a file and the field `raw_msg` which contains the error-message itself without code-lines and additional helpers. An exemplary output may look like this: ``` [nix-shell]$ ./inst/bin/nix-instantiate ~/test.nix --log-format minimal {"action":"msg","column":1,"file":"/home/ma27/test.nix","level":0,"line":4,"raw_msg":"syntax error, unexpected IF, expecting $end","msg":"<full error-msg with code-lines etc>"} ``` [1] https://github.com/dense-analysis/ale
afaics all comments are resolved. Anything else to add @edolstra? |
ping @edolstra anything else tbd to get this merged? |
ping @edolstra @Ericson2314 |
In the (unreleased) Nix 2.4 the error-messages have been reformatted[1]. This patch aims to retain proper `.nix`-support in `ale`, but is only targeted for folks using an unstable Nix version. Please note that this currently depends on a pending PR[2] which adds support for minimal JSON error-outputs. [1] NixOS/nix#3590 [2] NixOS/nix#3847
The new error-format is pretty nice from a UX point-of-view, however
it's fairly hard to parse the output e.g. for editor plugins such as
vim-ale[1] that use
nix-instantiate --parse
to determine syntax errors inNix expression files.
This patch extends the
internal-json
logger by adding the fieldsline
,column
andfile
to easily locate an error in a file and thefield
raw_msg
which contains the error-message itself withoutcode-lines and additional helpers.
An exemplary output may look like this:
[1] https://github.com/dense-analysis/ale