From bb196f43d9d77fe3c9eb38760ae6fce691b0bcc9 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 12 Mar 2024 09:42:09 -0700 Subject: [PATCH] `nix repl` `:print` always shows full errors --- src/libcmd/repl.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index a79d7c4821e..29d672b2344 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -114,19 +114,35 @@ struct NixRepl void evalString(std::string s, Value & v); void loadDebugTraceEnv(DebugTrace & dt); - void printValue(std::ostream & str, - Value & v, - unsigned int maxDepth = std::numeric_limits::max()) + /** + * Print a value to a maximum depth of 1. + */ + void printValueShallow(std::ostream & str, Value & v) { ::nix::printValue(*state, str, v, PrintOptions { .ansiColors = true, .force = true, .derivationPaths = true, - .maxDepth = maxDepth, + .maxDepth = 1, .prettyIndent = 2, .errors = ErrorPrintBehavior::ThrowTopLevel, }); } + + /** + * Print a value recursively. + */ + void printValueDeep(std::ostream & str, Value & v) + { + ::nix::printValue(*state, str, v, PrintOptions { + .ansiColors = true, + .force = true, + .derivationPaths = true, + .maxDepth = std::numeric_limits::max(), + .prettyIndent = 2, + .errors = ErrorPrintBehavior::Throw, + }); + } }; std::string removeWhitespace(std::string s) @@ -754,7 +770,7 @@ ProcessLineResult NixRepl::processLine(std::string line) if (v.type() == nString) { std::cout << v.string_view(); } else { - printValue(std::cout, v); + printValueDeep(std::cout, v); } std::cout << std::endl; } @@ -817,7 +833,7 @@ ProcessLineResult NixRepl::processLine(std::string line) } else { Value v; evalString(line, v); - printValue(std::cout, v, 1); + printValueShallow(std::cout, v); std::cout << std::endl; } }