this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+7 -2
+7 -2
internal/pkg/builtin.go
··· 241 241 // TODO: store the underlying error explicitly 242 242 ret = wrapCallErr(call, &adt.Bottom{Err: errors.Promote(err, "")}) 243 243 } 244 + case string, fmt.Stringer: 245 + // A string or a stringer likely used as a panic value. 246 + ret = wrapCallErr(call, &adt.Bottom{ 247 + Err: errors.Newf(call.Pos(), "%s", err), 248 + }) 244 249 default: 245 - // Likely a string passed to panic. 250 + // Some other value used when panicking; likely a bug. 246 251 ret = wrapCallErr(call, &adt.Bottom{ 247 - Err: errors.Newf(call.Pos(), "%s", err), 252 + Err: errors.Newf(call.Pos(), "BUG: non-stringifiable %T", err), 248 253 }) 249 254 } 250 255 return ret