mirror of
https://github.com/NixOS/nix.git
synced 2025-11-24 11:19:35 +01:00
libexpr: add list index to deepSeq error traces
When deepSeq encounters an error while evaluating a list element, the error trace now includes the list index, making it easier to locate the problematic element.
This commit is contained in:
parent
59a566db13
commit
a812b6c6e6
3 changed files with 43 additions and 1 deletions
|
|
@ -2216,8 +2216,15 @@ void EvalState::forceValueDeep(Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (v.isList()) {
|
else if (v.isList()) {
|
||||||
|
size_t index = 0;
|
||||||
for (auto v2 : v.listView())
|
for (auto v2 : v.listView())
|
||||||
recurse(*v2);
|
try {
|
||||||
|
recurse(*v2);
|
||||||
|
index++;
|
||||||
|
} catch (Error & e) {
|
||||||
|
state.addErrorTrace(e, "while evaluating list element at index %1%", index);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}(v);
|
}(v);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
tests/functional/lang/eval-fail-deepseq-list-attr.err.exp
Normal file
25
tests/functional/lang/eval-fail-deepseq-list-attr.err.exp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
error:
|
||||||
|
… while calling the 'deepSeq' builtin
|
||||||
|
at /pwd/lang/eval-fail-deepseq-list-attr.nix:3:1:
|
||||||
|
2|
|
||||||
|
3| builtins.deepSeq [
|
||||||
|
| ^
|
||||||
|
4| 1
|
||||||
|
|
||||||
|
… while evaluating list element at index 1
|
||||||
|
|
||||||
|
… while evaluating the attribute 'b'
|
||||||
|
at /pwd/lang/eval-fail-deepseq-list-attr.nix:7:5:
|
||||||
|
6| a = 2;
|
||||||
|
7| b = throw "error in attr in list element";
|
||||||
|
| ^
|
||||||
|
8| }
|
||||||
|
|
||||||
|
… while calling the 'throw' builtin
|
||||||
|
at /pwd/lang/eval-fail-deepseq-list-attr.nix:7:9:
|
||||||
|
6| a = 2;
|
||||||
|
7| b = throw "error in attr in list element";
|
||||||
|
| ^
|
||||||
|
8| }
|
||||||
|
|
||||||
|
error: error in attr in list element
|
||||||
10
tests/functional/lang/eval-fail-deepseq-list-attr.nix
Normal file
10
tests/functional/lang/eval-fail-deepseq-list-attr.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Test that deepSeq reports list index and attribute name in error traces.
|
||||||
|
|
||||||
|
builtins.deepSeq [
|
||||||
|
1
|
||||||
|
{
|
||||||
|
a = 2;
|
||||||
|
b = throw "error in attr in list element";
|
||||||
|
}
|
||||||
|
3
|
||||||
|
] "unexpected success"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue