| 9 Jun 2026 |
llakala | but of course: | 10:32:40 |
llakala |  Download image.png | 10:32:44 |
toonn | Why not builtins.attrNames? | 10:33:36 |
llakala | because we want to only show the attrNames on an error | 10:35:35 |
llakala | and addErrorContext does nothing here | 10:35:46 |
llakala | since it's only applied when evaluating a value fails, not its attributes | 10:36:00 |
llakala | ah interesting, i guess parentheses help here | 10:40:01 |
llakala | this doesn't work:
let
applyGetter = set: getter: builtins.addErrorContext "hi" getter set;
in
applyGetter {
foo = 1;
} (set: set.bar)
| 10:40:11 |
llakala | but this does:
let
applyGetter = set: getter: builtins.addErrorContext "hi" (getter set);
in
applyGetter {
foo = 1;
} (set: set.bar)
| 10:40:29 |
Matt Sturgeon | The difference is the first adds error context to the expression getter (which evaluates to a lambda), while the second adds error context to the expression (getter set) which applies the lambda. | 10:55:20 |
llakala | yeah, i get the concept - i just did it on instinct | 10:56:03 |
llakala | and assumed that i'd hit the issue with accessing attributes | 10:56:29 |
Matt Sturgeon |
is there any way to add error context for attempting to access an attribute that doesn't exist?
Yes:
nix-repl> builtins.addErrorContext "hi" {}.foo
error:
… hi
error: attribute 'foo' missing
at «string»:1:31:
1| builtins.addErrorContext "hi" {}.foo
| ^
Does this answer the question?
we want to only show the attrNames on an error
nix-repl> printOnErr = set: name: builtins.addErrorContext "${name} not found. Available are: ${toString (builtins.attrNames set)}" set.${name}
nix-repl> printOnErr { foo = null; bar = null; } "hello"
error:
… hello not found. Available are: bar foo
error: attribute 'hello' missing
at «string»:1:123:
1| printOnErr = set: name: builtins.addErrorContext "${name} not found. Available are: ${toString (builtins.attrNames set)}" set.${name}
| ^
| 11:03:01 |
llakala | unfortunately my API mandates that we actually let the user define a function, since they can nest an arbitrary level deep | 11:04:30 |
llakala | but i was able to get an error working | 11:04:51 |
llakala | just added some context way on the outside around callFunction and checked functionArgs there to determine which attr the user actually wanted | 11:05:31 |
llakala | not sure if it'll work for nested calls to recurse, but at least i now know it's possible | 11:05:44 |
| @vtcxyz_dmf:matrix.org joined the room. | 17:11:37 |
| @vtcxyz_dmf:matrix.org left the room. | 17:12:10 |
| 10 Jun 2026 |
| sharp-dressed-man changed their display name from g8dg5_s-+s50=z/ to sharp-dressed-man. | 08:08:20 |
| Nuwa changed their profile picture. | 15:40:49 |
| Nuwa changed their profile picture. | 15:47:04 |
| Nuwa changed their profile picture. | 16:34:14 |
| Nuwa changed their profile picture. | 16:34:41 |
| Nuwa changed their profile picture. | 16:56:04 |
| Nuwa changed their profile picture. | 16:58:04 |
| wduo87391 joined the room. | 18:03:16 |
| vmfunc changed their profile picture. | 20:49:21 |
| 11 Jun 2026 |
| @jowburner:matrix.org left the room. | 07:37:19 |
| dimothy joined the room. | 14:23:52 |