mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
lib.warn: Use or behave like builtins.warn
This commit is contained in:
parent
76e6d8b1a8
commit
f7250f372a
@ -12,6 +12,9 @@ let
|
|||||||
version
|
version
|
||||||
versionSuffix
|
versionSuffix
|
||||||
warn;
|
warn;
|
||||||
|
inherit (lib)
|
||||||
|
isString
|
||||||
|
;
|
||||||
in {
|
in {
|
||||||
|
|
||||||
## Simple (higher order) functions
|
## Simple (higher order) functions
|
||||||
@ -698,9 +701,18 @@ in {
|
|||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
warn =
|
warn =
|
||||||
if lib.elem (builtins.getEnv "NIX_ABORT_ON_WARN") ["1" "true" "yes"]
|
# Since https://github.com/NixOS/nix/pull/10592
|
||||||
then msg: builtins.trace "[1;31mwarning: ${msg}[0m" (abort "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.")
|
builtins.warn or (
|
||||||
else msg: builtins.trace "[1;31mwarning: ${msg}[0m";
|
let mustAbort = lib.elem (builtins.getEnv "NIX_ABORT_ON_WARN") ["1" "true" "yes"];
|
||||||
|
in
|
||||||
|
# Do not eta reduce v, so that we have the same strictness as `builtins.warn`.
|
||||||
|
msg: v:
|
||||||
|
# `builtins.warn` requires a string message, so we enforce that in our implementation, so that callers aren't accidentally incompatible with newer Nix versions.
|
||||||
|
assert isString msg;
|
||||||
|
if mustAbort
|
||||||
|
then builtins.trace "[1;31mwarning: ${msg}[0m" (abort "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.")
|
||||||
|
else builtins.trace "[1;31mwarning: ${msg}[0m" v
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Like warn, but only warn when the first argument is `true`.
|
Like warn, but only warn when the first argument is `true`.
|
||||||
|
Loading…
Reference in New Issue
Block a user