mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
Merge pull request #5840 from tweag/balsoft/nix-repl-show-trace
nix repl: fix --show-trace and add the ability to set trace display
This commit is contained in:
commit
70dfcbbb37
5 changed files with 27 additions and 3 deletions
|
@ -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.
|
||||
|
|
|
@ -25,7 +25,7 @@ const string & BaseError::calcWhat() const
|
|||
err.name = sname();
|
||||
|
||||
std::ostringstream oss;
|
||||
showErrorInfo(oss, err, false);
|
||||
showErrorInfo(oss, err, loggerSettings.showTrace);
|
||||
what_ = oss.str();
|
||||
|
||||
return *what_;
|
||||
|
|
|
@ -430,7 +430,8 @@ bool NixRepl::processLine(string line)
|
|||
<< " :t <expr> Describe result of evaluation\n"
|
||||
<< " :u <expr> Build derivation, then start nix-shell\n"
|
||||
<< " :doc <expr> Show documentation of a builtin function\n"
|
||||
<< " :log <expr> Show logs for a derivation\n";
|
||||
<< " :log <expr> 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);
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@ failing = import ./simple-failing.nix
|
|||
:log failing
|
||||
"
|
||||
|
||||
replUndefinedVariable="
|
||||
import ./undefined-variable.nix
|
||||
"
|
||||
|
||||
testRepl () {
|
||||
local nixArgs=("$@")
|
||||
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replCmds")"
|
||||
|
@ -22,10 +26,14 @@ testRepl () {
|
|||
nix path-info "${nixArgs[@]}" "$outPath"
|
||||
# simple.nix prints a PATH during build
|
||||
echo "$replOutput" | grep -qs 'PATH=' || fail "nix repl :log doesn't output logs"
|
||||
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds")"
|
||||
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds" 2>&1)"
|
||||
echo "$replOutput"
|
||||
echo "$replOutput" | grep -qs 'This should fail' \
|
||||
|| fail "nix repl :log doesn't output logs for a failed derivation"
|
||||
local replOutput="$(nix repl --show-trace "${nixArgs[@]}" <<< "$replUndefinedVariable" 2>&1)"
|
||||
echo "$replOutput"
|
||||
echo "$replOutput" | grep -qs "while evaluating the file" \
|
||||
|| fail "nix repl --show-trace doesn't show the trace"
|
||||
}
|
||||
|
||||
# Simple test, try building a drv
|
||||
|
|
1
tests/undefined-variable.nix
Normal file
1
tests/undefined-variable.nix
Normal file
|
@ -0,0 +1 @@
|
|||
let f = builtins.toFile "test-file.nix" "asd"; in import f
|
Loading…
Reference in a new issue