haskell-jsonnet icon indicating copy to clipboard operation
haskell-jsonnet copied to clipboard

Debugging: add `std.trace`

Open moleike opened this issue 4 years ago • 0 comments

std.trace(str, rest) outputs the given string str to stderr and returns rest as the result.

Example:

local conditionalReturn(cond, in1, in2) =
  if (cond) then
      std.trace('cond is true returning '
              + std.toString(in1), in1)
  else
      std.trace('cond is false returning '
              + std.toString(in2), in2);

{
    a: conditionalReturn(true, { b: true }, { c: false }),
}

Prints:

TRACE: test.jsonnet:3 cond is true returning {"b": true}
{
    "a": {
        "b": true
    }
}

moleike avatar Jan 05 '21 11:01 moleike