libexpr: print value of what is attempted to be called as function

Low-hanging fruit in the spirit of #9753 and #9754 (means 9999years did
all the hard work already).

This basically prints out what was attempted to be called as function,
i.e.

  map (import <nixpkgs> {}) [ 1 2 3 ]

now gives the following error message:

    error:
           … while calling the 'map' builtin
             at «string»:1:1:
                1| map (import <nixpkgs> {}) [ 1 2 3 ]
                 | ^

           … while evaluating the first argument passed to builtins.map

           error: expected a function but found a set: { _type = "pkgs"; AAAAAASomeThingsFailToEvaluate = «thunk»; AMB-plugins = «thunk»; ArchiSteamFarm = «thunk»; BeatSaberModManager = «thunk»; CHOWTapeModel = «thunk»; ChowCentaur = «thunk»; ChowKick = «thunk»; ChowPhaser = «thunk»; CoinMP = «thunk»;  «18783 attributes elided»}
This commit is contained in:
Maximilian Bosch 2024-01-20 16:05:30 +01:00
parent 5f72a97092
commit 81499a0b93
No known key found for this signature in database
2 changed files with 7 additions and 3 deletions

View File

@ -1692,7 +1692,11 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
}
else
error("attempt to call something which is not a function but %1%", showType(vCur)).atPos(pos).debugThrow<TypeError>();
error("attempt to call something which is not a function but %1%: %2%",
showType(vCur),
ValuePrinter(*this, vCur, errorPrintOptions))
.atPos(pos)
.debugThrow<TypeError>();
}
vRes = vCur;

View File

@ -750,7 +750,7 @@ namespace nix {
ASSERT_TRACE1("foldl' (_: 1) \"foo\" [ true ]",
TypeError,
hintfmt("attempt to call something which is not a function but %s", "an integer"));
hintfmt("attempt to call something which is not a function but %s: %s", "an integer", ANSI_CYAN "1" ANSI_NORMAL));
ASSERT_TRACE2("foldl' (a: b: a && b) \"foo\" [ true ]",
TypeError,
@ -835,7 +835,7 @@ namespace nix {
ASSERT_TRACE1("sort (_: 1) [ \"foo\" \"bar\" ]",
TypeError,
hintfmt("attempt to call something which is not a function but %s", "an integer"));
hintfmt("attempt to call something which is not a function but %s: %s", "an integer", ANSI_CYAN "1" ANSI_NORMAL));
ASSERT_TRACE2("sort (_: _: 1) [ \"foo\" \"bar\" ]",
TypeError,