-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added `builtins.toStringDebug`, which formats a value as a string for debugging purposes. Unlike `builtins.toString`, `builtins.toStringDebug` will never error and will always produce human-readable, pretty-printed output (including for expressions that error). This makes it ideal for interpolation into `builtins.trace` calls and `assert` messages.
- Loading branch information
Showing
8 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
synopsis: Add `builtins.toStringDebug` | ||
prs: | ||
--- | ||
|
||
Added `builtins.toStringDebug`, which formats a value as a string for debugging | ||
purposes. Unlike `builtins.toString`, `builtins.toStringDebug` will never error | ||
and will always produce human-readable, pretty-printed output (including for | ||
expressions that error). This makes it ideal for interpolation into | ||
`builtins.trace` calls and `assert` messages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "primops.hh" | ||
#include "print-options.hh" | ||
|
||
namespace nix { | ||
|
||
static void prim_toStringDebug(EvalState & state, const PosIdx pos, Value * * args, Value & v) | ||
{ | ||
v.mkString(printValue(state, *args[0], debugPrintOptions)); | ||
} | ||
|
||
static RegisterPrimOp primop_toStringDebug({ | ||
.name = "toStringDebug", | ||
.args = {"value"}, | ||
.doc = R"( | ||
Format a value as a string for debugging purposes. | ||
Unlike [`toString`](@docroot@/language/builtins.md#builtins-toString), | ||
`toStringDebug` will never error and will always produce human-readable | ||
output (including for values that throw errors). For this reason, | ||
`toStringDebug` is ideal for interpolation into messages in | ||
[`trace`](@docroot@/language/builtins.md#builtins-trace) | ||
calls and [`assert`](@docroot@/language/constructs.html#assertions) | ||
statements. | ||
Output will be pretty-printed and include ANSI escape sequences. | ||
If the value contains too many values (for instance, more than 32 | ||
attributes or list items), some values will be elided. | ||
)", | ||
.fun = prim_toStringDebug, | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
trace: [ «thunk» ] | ||
trace: [ | ||
2 | ||
] |