!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1927 Members
Nix programming language358 Servers

Load older messages


SenderMessageTime
9 Jun 2026
@llakala:matrix.orgllakalabut of course:10:32:40
@llakala:matrix.orgllakalaimage.png
Download image.png
10:32:44
@toonn:matrix.orgtoonn Why not builtins.attrNames? 10:33:36
@llakala:matrix.orgllakalabecause we want to only show the attrNames on an error10:35:35
@llakala:matrix.orgllakalaand addErrorContext does nothing here10:35:46
@llakala:matrix.orgllakalasince it's only applied when evaluating a value fails, not its attributes10:36:00
@llakala:matrix.orgllakalaah interesting, i guess parentheses help here10:40:01
@llakala:matrix.orgllakala

this doesn't work:

let
  applyGetter = set: getter: builtins.addErrorContext "hi" getter set;
in
applyGetter {
  foo = 1;
} (set: set.bar)
10:40:11
@llakala:matrix.orgllakala

but this does:

let
  applyGetter = set: getter: builtins.addErrorContext "hi" (getter set);
in
applyGetter {
  foo = 1;
} (set: set.bar)
10:40:29
@mattsturg:matrix.orgMatt 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:matrix.orgllakalayeah, i get the concept - i just did it on instinct10:56:03
@llakala:matrix.orgllakalaand assumed that i'd hit the issue with accessing attributes10:56:29
@mattsturg:matrix.orgMatt 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:matrix.orgllakalaunfortunately my API mandates that we actually let the user define a function, since they can nest an arbitrary level deep11:04:30
@llakala:matrix.orgllakalabut i was able to get an error working11:04:51
@llakala:matrix.orgllakala 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:matrix.orgllakala 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@vtcxyz_dmf:matrix.org joined the room.17:11:37
@vtcxyz_dmf:matrix.org@vtcxyz_dmf:matrix.org left the room.17:12:10
10 Jun 2026
@g8dg5_s-+s50=z/:matrix.orgsharp-dressed-man changed their display name from g8dg5_s-+s50=z/ to sharp-dressed-man.08:08:20
@lumi:the-apothecary.clubNuwa changed their profile picture.15:40:49
@lumi:the-apothecary.clubNuwa changed their profile picture.15:47:04
@lumi:the-apothecary.clubNuwa changed their profile picture.16:34:14
@lumi:the-apothecary.clubNuwa changed their profile picture.16:34:41
@lumi:the-apothecary.clubNuwa changed their profile picture.16:56:04
@lumi:the-apothecary.clubNuwa changed their profile picture.16:58:04
@kongyuezhiling:mozilla.orgwduo87391 joined the room.18:03:16
@vmfunc:mozilla.orgvmfunc changed their profile picture.20:49:21
11 Jun 2026
@jowburner:matrix.org@jowburner:matrix.org left the room.07:37:19
@dimars86:matrix.orgdimothy joined the room.14:23:52

Show newer messages


Back to Room ListRoom Version: 6