internal/pkg: only use %s with stringifiable builtin errors
https://cuelang.org/issue/3972 surfaces an evaluator error
where the internal scheduler panics with a pointer to itself to "yield",
but that panic ends up being processed as an error instead:
output.out1: error in call to encoding/yaml.Marshal: &{%!s(*adt.OpContext=&{0xc000320100 0x762d60 ...
While we figure out the underlying bug, at least we can make the code
a bit more defensive so that we never try using the %s formatting verb
on error values which are not string or fmt.Stringer.
That can easily lead to hundreds of nonsensical characters as a single
verbose line, such as the case above with an *adt.scheduler value.
We now get a much shorter error message, which at least points the user
towards an internal evaluator bug, and which type is involved:
output.out1: error in call to encoding/yaml.Marshal: BUG: non-stringifiable *adt.scheduler:
We're not adding a test because such panics should never occur
unless there's a bug in the evaluator. There is one today,
but we aim to fix the bug very shortly.
For #3972.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I6ec830055bc5814216795385fd75216aae206111
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1217060
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>