mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
libexpr: improve error messages for builtins.genericClosure
Show which element(s) are involved at each error point: - When an element is missing the "key" attribute, show the element - When an element is not an attribute set, show the element - When comparing keys fails, show both elements being compared - When calling operator fails, show which element was being processed This provides concrete context using ValuePrinter with errorPrintOptions. Note: errorPrintOptions uses maxDepth=10 by default, which may print quite deeply nested structures in error messages. This could potentially be overwhelming, but follows the existing default for error contexts.
This commit is contained in:
parent
ca787bc3e0
commit
d262efc240
10 changed files with 188 additions and 46 deletions
|
|
@ -0,0 +1,18 @@
|
|||
error:
|
||||
… while calling the 'seq' builtin
|
||||
at /pwd/lang/eval-fail-genericClosure-deeply-nested-element.nix:25:1:
|
||||
24| in
|
||||
25| builtins.seq finiteVal (
|
||||
| ^
|
||||
26| builtins.genericClosure {
|
||||
|
||||
… while calling the 'genericClosure' builtin
|
||||
at /pwd/lang/eval-fail-genericClosure-deeply-nested-element.nix:26:3:
|
||||
25| builtins.seq finiteVal (
|
||||
26| builtins.genericClosure {
|
||||
| ^
|
||||
27| startSet = [
|
||||
|
||||
… in genericClosure element { finite = { a0 = { a1 = { a2 = { a3 = { a4 = { a5 = { a6 = { a7 = { a8 = { ... }; }; }; }; }; }; }; }; }; }; «1 attribute elided» }
|
||||
|
||||
error: attribute 'key' missing
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
let
|
||||
finite = {
|
||||
a0 = {
|
||||
a1 = {
|
||||
a2 = {
|
||||
a3 = {
|
||||
a4 = {
|
||||
a5 = {
|
||||
a6 = {
|
||||
a7 = {
|
||||
a8 = {
|
||||
a9 = "deep";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
finiteVal = builtins.deepSeq finite finite;
|
||||
in
|
||||
builtins.seq finiteVal (
|
||||
builtins.genericClosure {
|
||||
startSet = [
|
||||
{
|
||||
infinite = import ./infinite-nesting.nix;
|
||||
finite = finiteVal;
|
||||
}
|
||||
];
|
||||
operator = x: [ (import ./infinite-nesting.nix) ];
|
||||
}
|
||||
)
|
||||
|
|
@ -5,6 +5,6 @@ error:
|
|||
| ^
|
||||
2| startSet = [ { nokey = 1; } ];
|
||||
|
||||
… in one of the attrsets generated by (or initially passed to) builtins.genericClosure
|
||||
… in genericClosure element { nokey = 1; }
|
||||
|
||||
error: attribute 'key' missing
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ error:
|
|||
| ^
|
||||
2| startSet = [ "not an attrset" ];
|
||||
|
||||
… while evaluating one of the elements generated by (or initially passed to) builtins.genericClosure
|
||||
… in genericClosure element "not an attrset"
|
||||
|
||||
error: expected a set but found a string: "not an attrset"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ error:
|
|||
| ^
|
||||
2| startSet = [
|
||||
|
||||
… while comparing the `key` attributes of two genericClosure elements
|
||||
… while comparing element { key = "string"; }
|
||||
|
||||
error: cannot compare a string with an integer
|
||||
… with element { key = 1; }
|
||||
|
||||
error: cannot compare a string with an integer; values are "string" and 1
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ error:
|
|||
| ^
|
||||
2| startSet = [
|
||||
|
||||
… while comparing the `key` attributes of two genericClosure elements
|
||||
… while comparing element { key = { }; }
|
||||
|
||||
error: cannot compare a set with a set; values of that type are incomparable
|
||||
… with element { key = { }; }
|
||||
|
||||
error: cannot compare a set with a set; values of that type are incomparable (values are { } and { })
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ error:
|
|||
| ^
|
||||
2| startSet = [ { key = 1; } ];
|
||||
|
||||
… while calling operator on genericClosure element { key = 1; }
|
||||
|
||||
… while evaluating the return value of the `operator` passed to builtins.genericClosure
|
||||
|
||||
error: expected a list but found a string: "not a list"
|
||||
|
|
|
|||
4
tests/functional/lang/infinite-nesting.nix
Normal file
4
tests/functional/lang/infinite-nesting.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let
|
||||
mkInfinite = i: { "a${toString i}" = mkInfinite (i + 1); };
|
||||
in
|
||||
mkInfinite 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue