vitessio/vitess · error
panic(err)
Error message
panic(err)
What it means
EvalResult.MustBoolean asserts that the result can be strictly converted to a boolean; if ToBooleanStrict returns an error the Must* contract panics with that error. Must* methods are for call sites that already know the value is boolean-coercible.
Source
Thrown at go/vt/vtgate/evalengine/eval_result.go:86
// TupleValues allows for retrieval of the value we expose for public consumption
func (er EvalResult) TupleValues() []sqltypes.Value {
// TODO: Make this collation-aware
switch v := er.v.(type) {
case *evalTuple:
result := make([]sqltypes.Value, 0, len(v.t))
for _, val := range v.t {
result = append(result, evalToSQLValue(val))
}
return result
default:
return nil
}
}
func (er EvalResult) MustBoolean() bool {
b, err := er.ToBooleanStrict()
if err != nil {
panic(err)
}
return b
}
func (er EvalResult) ToBoolean() bool {
return evalIsTruthy(er.v) == boolTrue
}
// ToBooleanStrict is used when the casting to a boolean has to be minimally forgiving,
// such as when assigning to a system variable that is expected to be a boolean
func (er EvalResult) ToBooleanStrict() (bool, error) {
switch v := er.v.(type) {
case *evalInt64:
switch v.i {
case 0:
return false, nil
case 1:
return true, nilView on GitHub (pinned to 01a25a7d17)
Solutions
- Replace MustBoolean with ToBooleanStrict and handle the error
- Only call MustBoolean on results known to come from boolean-producing expressions
- Add a type/type check on the underlying value before calling
Example fix
// before
b := result.MustBoolean()
// after
b, err := result.ToBooleanStrict()
if err != nil {
return vterrors.Wrapf(err, "expected boolean result")
} Defensive patterns
Strategy: try-catch
Validate before calling
// check strict convertibility first
if _, err := er.ToBooleanStrict(); err != nil {
return vterrors.Wrapf(err, "result is not a boolean")
} Type guard
func isStrictBoolean(er EvalResult) bool {
_, err := er.ToBooleanStrict()
return err == nil
} Try / catch
func safeMustBoolean(er EvalResult) (b bool, err error) {
defer func() {
if r := recover(); r != nil {
err = vterrors.Errorf(vtrpcpb.Code_INTERNAL, "MustBoolean: %v", r)
}
}()
return er.MustBoolean(), nil
} Prevention
- Prefer ToBooleanStrict in library/infrastructure code; reserve Must* for invariant-proven call sites
- Only call MustBoolean on results of boolean expressions (comparisons, logical ops)
- Document on wrappers that the input must be boolean-producing
When it happens
Trigger: Calling MustBoolean on an EvalResult whose underlying value is not strictly boolean — e.g. a string, integer, or NULL result from expression evaluation passed to MustBoolean.
Common situations: Developers using MustBoolean on arbitrary query results instead of checking ToBooleanStrict first; value returned from a comparison changed shape after a refactor.
Related errors
- malformed hex literal from parser
- bad unsigned integer type
- bad type aggregation for signed/unsigned types
- unreachable
- unhandled case: evalIsTruthy
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/6f17dd11e9056c96.
Report an issue: GitHub.