Skip to content

Commit

Permalink
nix repl :print always shows full errors
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Mar 12, 2024
1 parent c9c922f commit bb196f4
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>::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<size_t>::max(),
.prettyIndent = 2,
.errors = ErrorPrintBehavior::Throw,
});
}
};

std::string removeWhitespace(std::string s)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit bb196f4

Please sign in to comment.