mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
builtins.warn: Require string argument
... so that we may perhaps later extend the interface. Note that Nixpkgs' lib.warn already requires a string coercible argument, so this is reasonable. Also note that string coercible values aren't all strings, but in practice, for warn, they are.
This commit is contained in:
parent
923cbea2af
commit
da82d67022
2 changed files with 8 additions and 10 deletions
|
@ -1045,16 +1045,12 @@ static RegisterPrimOp primop_trace({
|
|||
|
||||
static void prim_warn(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||
{
|
||||
state.forceValue(*args[0], pos);
|
||||
// We only accept a string argument for now. The use case for pretty printing a value is covered by `trace`.
|
||||
// By rejecting non-strings we allow future versions to add more features without breaking existing code.
|
||||
auto msgStr = state.forceString(*args[0], pos, "while evaluating the first argument; the message passed to builtins.warn");
|
||||
|
||||
{
|
||||
BaseError msg(args[0]->type() == nString
|
||||
? std::string(args[0]->string_view())
|
||||
: ({
|
||||
std::stringstream s;
|
||||
s << ValuePrinter(state, *args[0]);
|
||||
s.str();
|
||||
}));
|
||||
BaseError msg(std::string{msgStr});
|
||||
msg.atPos(state.positions[pos]);
|
||||
auto info = msg.info();
|
||||
info.level = lvlWarn;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue