From 81499a0b93a136f889f3799d7110dcc479a4cbe1 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 20 Jan 2024 16:05:30 +0100 Subject: [PATCH] libexpr: print value of what is attempted to be called as function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 {}) [ 1 2 3 ] now gives the following error message: error: … while calling the 'map' builtin at «string»:1:1: 1| map (import {}) [ 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»} --- src/libexpr/eval.cc | 6 +++++- tests/unit/libexpr/error_traces.cc | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 71e956e10..ce410162e 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -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(); + error("attempt to call something which is not a function but %1%: %2%", + showType(vCur), + ValuePrinter(*this, vCur, errorPrintOptions)) + .atPos(pos) + .debugThrow(); } vRes = vCur; diff --git a/tests/unit/libexpr/error_traces.cc b/tests/unit/libexpr/error_traces.cc index f0cad58bb..f99aafd74 100644 --- a/tests/unit/libexpr/error_traces.cc +++ b/tests/unit/libexpr/error_traces.cc @@ -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,