diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 47f202b..f9ca986 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include @@ -35,6 +37,7 @@ struct MyArgs : MixEvalArgs, MixCommonArgs Path gcRootsDir; bool flake = false; bool meta = false; + bool showTrace = false; size_t nrWorkers = 1; size_t maxMemorySize = 4096; pureEval evalMode = evalAuto; @@ -101,6 +104,12 @@ struct MyArgs : MixEvalArgs, MixCommonArgs .handler = {&meta, true} }); + addFlag({ + .longName = "show-trace", + .description = "print out a stack trace in case of evaluation errors", + .handler = {&showTrace, true} + }); + expectArg("expr", &releaseExpr); } }; @@ -241,13 +250,18 @@ static void worker( else throw TypeError("attribute '%s' is %s, which is not supported", attrPath, showType(*v)); } catch (EvalError & e) { - auto msg = e.msg(); + auto err = e.info(); + + std::ostringstream oss; + showErrorInfo(oss, err, loggerSettings.showTrace.get()); + auto msg = oss.str(); + // Transmits the error we got from the previous evaluation // in the JSON output. reply["error"] = filterANSIEscapes(msg, true); // Don't forget to print it into the STDERR log, this is // what's shown in the Hydra UI. - printError(msg); + printError(e.msg()); } writeLine(to.get(), reply.dump()); @@ -289,6 +303,10 @@ int main(int argc, char * * argv) if (myArgs.gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified"); + if (myArgs.showTrace) { + loggerSettings.showTrace.assign(true); + } + struct State { std::set todo{""};