grafana/k6 · error
' ' is an invalid value for metric ' ', a number or a…
Error message
'%s' is an invalid value for metric '%s', a number or a boolean value is expected
What it means
Produced by the raiseNan helper inside Metric.add when the value passed to Counter.add/Value.add etc. cannot be coerced to a number. After sobek coercion the value's float is NaN (e.g. null, a non-numeric string) while its boolean coercion is true; the invalid value (length-limited to 100 chars) and metric name are reported. Depending on the throw option this is either returned as an error or only logged as a warning while add() returns false.
Solutions
- Pass a number or boolean to the metric's add() method, e.g. myCounter.add(1)
- For boolean semantics use true (recorded as 1) rather than null or strings
- Check state.Options.Throw: with throw disabled the error is only a warning and the sample is silently dropped
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/metrics/metrics.go:92 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/eaedacdb01251f60.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/metrics/metrics.go:92
}, string(omitMsg))
}
func (m Metric) add(v sobek.Value, addTags sobek.Value) (bool, error) {
state := m.vu.State()
if state == nil {
return false, ErrMetricsAddInInitContext
}
// return/throw exception if throw enabled, otherwise just log
raiseErr := func(err error) (bool, error) { //nolint:unparam // we want to just do `return raiseErr(...)`
if state.Options.Throw.Bool {
return false, err
}
state.Logger.Warn(err)
return false, nil
}
raiseNan := func() (bool, error) {
return raiseErr(fmt.Errorf("'%s' is an invalid value for metric '%s', a number or a boolean value is expected",
limitValue(v.String()), m.metric.Name))
}
if v == nil {
return raiseErr(fmt.Errorf("no value was provided for metric '%s', a number or a boolean value is expected",
m.metric.Name))
}
if sobek.IsNull(v) {
return raiseNan()
}
vfloat := v.ToFloat()
if vfloat == 0 && v.ToBoolean() {
vfloat = 1.0
}
if math.IsNaN(vfloat) {
return raiseNan()View on GitHub (pinned to 01ffac6f24)