Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only print the first line of errors in values #10207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion src/libexpr/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,12 @@ class Printer
{
if (options.ansiColors)
output << ANSI_RED;
output << "«error: " << filterANSIEscapes(e.info().msg.str(), true) << "»";
auto message = filterANSIEscapes(e.info().msg.str(), true);
auto newline = message.find('\n');
if (newline != std::string::npos) {
message = message.substr(0, newline);
}
output << "«error: " << message << "»";
if (options.ansiColors)
output << ANSI_NORMAL;
}
Expand Down
Loading