mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
toJSON: Add attribute path to trace
This commit is contained in:
parent
2d1d81114d
commit
33d58a90c2
4 changed files with 88 additions and 3 deletions
|
@ -43,6 +43,7 @@ json printValueAsJSON(EvalState & state, bool strict,
|
|||
break;
|
||||
|
||||
case nNull:
|
||||
// already initialized as null
|
||||
break;
|
||||
|
||||
case nAttrs: {
|
||||
|
@ -59,7 +60,13 @@ json printValueAsJSON(EvalState & state, bool strict,
|
|||
names.emplace(state.symbols[j.name]);
|
||||
for (auto & j : names) {
|
||||
Attr & a(*v.attrs->find(state.symbols.create(j)));
|
||||
out[j] = printValueAsJSON(state, strict, *a.value, a.pos, context, copyToStore);
|
||||
try {
|
||||
out[j] = printValueAsJSON(state, strict, *a.value, a.pos, context, copyToStore);
|
||||
} catch (Error & e) {
|
||||
e.addTrace(state.positions[a.pos],
|
||||
hintfmt("while evaluating attribute '%1%'", j));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
} else
|
||||
return printValueAsJSON(state, strict, *i->value, i->pos, context, copyToStore);
|
||||
|
@ -68,8 +75,17 @@ json printValueAsJSON(EvalState & state, bool strict,
|
|||
|
||||
case nList: {
|
||||
out = json::array();
|
||||
for (auto elem : v.listItems())
|
||||
out.push_back(printValueAsJSON(state, strict, *elem, pos, context, copyToStore));
|
||||
int i = 0;
|
||||
for (auto elem : v.listItems()) {
|
||||
try {
|
||||
out.push_back(printValueAsJSON(state, strict, *elem, pos, context, copyToStore));
|
||||
} catch (Error & e) {
|
||||
e.addTrace({},
|
||||
hintfmt("while evaluating list element at index %1%", i));
|
||||
throw;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue