1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 18:31:49 +02:00

libutil/logging: extend internal-json logger to make it more machine-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
This commit is contained in:
Maximilian Bosch 2020-07-21 23:38:18 +02:00
parent ff314f186e
commit 6ccfdb79c7
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
3 changed files with 53 additions and 1 deletions

View file

@ -106,7 +106,14 @@
</varlistentry>
<varlistentry><term>internal-json</term>
<listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
<listitem>
<para>Outputs the logs in a structured manner.</para>
<warning>
<para>
While the schema itself is relatively stable, the format of the error-messages (namely of the <literal>msg</literal>-field) can change between several releases.
</para>
</warning>
</listitem>
</varlistentry>
<varlistentry><term>bar</term>