mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
toJSON: report error position for fancier output
Given flake:
```nix
{ description = "nix json error provenance";
inputs = {};
outputs = { self }: {
jsonFunction = _: "function";
json = builtins.toJSON (_: "function");
};
}
```
- Before:
```console
❯ nix eval --json .#jsonFunction
error: cannot convert a function to JSON
```
- After:
```console
❯ nix eval --json .#jsonFunction
error: cannot convert a function to JSON
at /nix/store/b7imf1c2j4jnkg3ys7fsfbj02s5j0i4f-source/testflake/flake.nix:4:5:
3| outputs = { self }: {
4| jsonFunction = _: "function";
| ^
5| json = builtins.toJSON (_: "function");
```
This commit is contained in:
parent
4a2b7cc68c
commit
ba81e871b2
6 changed files with 22 additions and 16 deletions
|
|
@ -1008,7 +1008,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (i->name == state.sStructuredAttrs) continue;
|
||||
|
||||
auto placeholder(jsonObject->placeholder(key));
|
||||
printValueAsJSON(state, true, *i->value, placeholder, context);
|
||||
printValueAsJSON(state, true, *i->value, pos, placeholder, context);
|
||||
|
||||
if (i->name == state.sBuilder)
|
||||
drv.builder = state.forceString(*i->value, context, posDrvName);
|
||||
|
|
@ -1687,7 +1687,7 @@ static void prim_toJSON(EvalState & state, const Pos & pos, Value * * args, Valu
|
|||
{
|
||||
std::ostringstream out;
|
||||
PathSet context;
|
||||
printValueAsJSON(state, true, *args[0], out, context);
|
||||
printValueAsJSON(state, true, *args[0], pos, out, context);
|
||||
mkString(v, out.str(), context);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue