nix3-eval: don't elide top-level errors
Fixes #276. Change-Id: I83e71beb5c35d6f3b10a4186caa5e52a2f95b510
This commit is contained in:
parent
8822fd7dd5
commit
54322f09d3
2 changed files with 12 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "command-installable-value.hh"
|
#include "command-installable-value.hh"
|
||||||
#include "common-args.hh"
|
#include "common-args.hh"
|
||||||
|
#include "print-options.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
|
@ -127,7 +128,8 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
|
||||||
*v,
|
*v,
|
||||||
PrintOptions {
|
PrintOptions {
|
||||||
.force = true,
|
.force = true,
|
||||||
.derivationPaths = true
|
.derivationPaths = true,
|
||||||
|
.errors = ErrorPrintBehavior::ThrowTopLevel,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,6 +22,15 @@ nix eval -E 'assert 1 + 2 == 3; true'
|
||||||
[[ $(nix eval int -f - < "./eval.nix") == 123 ]]
|
[[ $(nix eval int -f - < "./eval.nix") == 123 ]]
|
||||||
[[ "$(nix eval --expr '{"assert"=1;bar=2;}')" == '{ "assert" = 1; bar = 2; }' ]]
|
[[ "$(nix eval --expr '{"assert"=1;bar=2;}')" == '{ "assert" = 1; bar = 2; }' ]]
|
||||||
|
|
||||||
|
# Top-level eval errors should be printed to stderr with a traceback.
|
||||||
|
topLevelThrow="$(expectStderr 1 nix eval --expr 'throw "a sample throw message"')"
|
||||||
|
[[ "$topLevelThrow" =~ "a sample throw message" ]]
|
||||||
|
[[ "$topLevelThrow" =~ "while calling the 'throw' builtin" ]]
|
||||||
|
|
||||||
|
# But errors inside something should print an elided version, and exit with 0.
|
||||||
|
outputOfNestedThrow="$(nix eval --expr '{ throws = throw "a sample throw message"; }')"
|
||||||
|
[[ "${outputOfNestedThrow}" == "{ throws = «error: a sample throw message»; }" ]]
|
||||||
|
|
||||||
# Check if toFile can be utilized during restricted eval
|
# Check if toFile can be utilized during restricted eval
|
||||||
[[ $(nix eval --restrict-eval --expr 'import (builtins.toFile "source" "42")') == 42 ]]
|
[[ $(nix eval --restrict-eval --expr 'import (builtins.toFile "source" "42")') == 42 ]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue