new option: abort-on-warn
Co-authored-by: Emilia Bopp <contact@ebopp.de> Change-Id: I3c3347e51d8543fbeb2b4e6ed12b0f556a6a6964
This commit is contained in:
@@ -10,4 +10,6 @@ Like `builtins.trace`, it takes two arguments: the message to emit, and the expr
|
||||
_Unlike_ `builtins.trace`, `builtins.warn` requires the first argument — the message — to be a string.
|
||||
In the future we may extend `builtins.warn` to accept a more structured API.
|
||||
|
||||
To go along with this, we also have a new config setting [`debugger-on-warn`](@docroot@/command-ref/conf-file.md#conf-debugger-on-warn), which, when used with `--debugger`, makes `builtins.warn` also function like [`builtins.break`](@docroot@/language/builtins.md#builtins-break).
|
||||
To go along with this, we also have two new config settings:
|
||||
- [`debugger-on-warn`](@docroot@/command-ref/conf-file.md#conf-debugger-on-warn), which, when used with `--debugger`, makes `builtins.warn` also function like [`builtins.break`](@docroot@/language/builtins.md#builtins-break).
|
||||
- [`abort-on-warn`](@docroot@/command-ref/conf-file.md#conf-abort-on-warn), which aborts evaluation entirely after the warning is emitted.
|
||||
|
||||
@@ -15,6 +15,7 @@ subdir('flake')
|
||||
|
||||
libexpr_setting_definitions = files(
|
||||
# keep-sorted start
|
||||
'settings/abort-on-warn.md',
|
||||
'settings/allow-import-from-derivation.md',
|
||||
'settings/allow-unsafe-native-code-during-evaluation.md',
|
||||
'settings/allowed-uris.md',
|
||||
|
||||
@@ -779,6 +779,11 @@ static void prim_warn(EvalState & state, Value ** args, Value & v)
|
||||
|
||||
printTaggedWarning("%s", Uncolored(msg));
|
||||
|
||||
if (evalSettings.abortOnWarn) {
|
||||
state.ctx.errors.make<Abort>("evaluation aborted (abort-on-warn)")
|
||||
.debugThrow();
|
||||
}
|
||||
|
||||
if (evalSettings.debuggerOnWarn) {
|
||||
if (auto const trace = state.ctx.nextDebugTrace()) {
|
||||
auto const error = EvalError(ErrorInfo{
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: abort-on-warn
|
||||
internalName: abortOnWarn
|
||||
type: bool
|
||||
default: false
|
||||
---
|
||||
If set to true, [`builtins.warn`](@docroot@/language/builtins.md#builtins-warn) will throw an error when logging a warning.
|
||||
This will give you a stack trace that leads to the location of the warning.
|
||||
This is useful for finding information about warnings in third-party Nix code when you can not start the interactive debugger, such as when Nix is called from a non-interactive script. See [`debugger-on-warn`](#conf-debugger-on-warn).
|
||||
Currently, a stack trace can only be produced when the debugger is enabled, or when evaluation is aborted.
|
||||
@@ -0,0 +1,9 @@
|
||||
warning: meow
|
||||
error:
|
||||
… while calling the 'warn' builtin
|
||||
at /pwd/in.nix:1:1:
|
||||
1| builtins.warn "meow" (throw "must abort before this")
|
||||
| ^
|
||||
2|
|
||||
|
||||
error: evaluation aborted (abort-on-warn)
|
||||
@@ -0,0 +1 @@
|
||||
builtins.warn "meow" (throw "must abort before this")
|
||||
@@ -4,3 +4,8 @@ runner = "eval-okay"
|
||||
[[test]]
|
||||
runner = "eval-fail"
|
||||
in = "in-reject-non-string.nix"
|
||||
|
||||
[[test]]
|
||||
runner = "eval-fail"
|
||||
flags = ["--option", "abort-on-warn", "true"]
|
||||
in = "in-abort.nix"
|
||||
|
||||
Reference in New Issue
Block a user