From a26351da02689d1e3ee562a6d89d93c12816e476 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Tue, 28 Dec 2021 16:13:07 +0300 Subject: [PATCH] Add ability to toggle show-trace from within the repl --- doc/manual/src/release-notes/rl-next.md | 2 ++ src/nix/repl.cc | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/manual/src/release-notes/rl-next.md b/doc/manual/src/release-notes/rl-next.md index ac662c132..2a67a39b1 100644 --- a/doc/manual/src/release-notes/rl-next.md +++ b/doc/manual/src/release-notes/rl-next.md @@ -2,3 +2,5 @@ * The TOML parser used by `builtins.fromTOML` has been replaced by [a more compliant one](https://github.com/ToruNiina/toml11). +* Added `:st`/`:show-trace` commands to nix repl, which are used to + set or toggle display of error traces. diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 39a5a31de..a62ad66c2 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -430,7 +430,8 @@ bool NixRepl::processLine(string line) << " :t Describe result of evaluation\n" << " :u Build derivation, then start nix-shell\n" << " :doc Show documentation of a builtin function\n" - << " :log Show logs for a derivation\n"; + << " :log Show logs for a derivation\n" + << " :st [bool] Enable, disable or toggle showing traces for errors\n"; } else if (command == ":a" || command == ":add") { @@ -572,6 +573,18 @@ bool NixRepl::processLine(string line) throw Error("value does not have documentation"); } + else if (command == ":st" || command == ":show-trace") { + if (arg == "false" || (arg == "" && loggerSettings.showTrace)) { + std::cout << "not showing error traces\n"; + loggerSettings.showTrace = false; + } else if (arg == "true" || (arg == "" && !loggerSettings.showTrace)) { + std::cout << "showing error traces\n"; + loggerSettings.showTrace = true; + } else { + throw Error("unexpected argument '%s' to %s", arg, command); + }; + } + else if (command != "") throw Error("unknown command '%1%'", command);