{"record":{"id":"856ed6c0d02e7bf2","repo":"grafana/k6","slug":"no-value-was-provided-for-metric-s-a-number-or","errorCode":null,"errorMessage":"no value was provided for metric '%s', a number or a boolean value is expected","messagePattern":"no value was provided for metric '(.+?)', a number or a boolean value is expected","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/metrics/metrics.go","lineNumber":97,"sourceCode":"\tif state == nil {\n\t\treturn false, ErrMetricsAddInInitContext\n\t}\n\n\t// return/throw exception if throw enabled, otherwise just log\n\traiseErr := func(err error) (bool, error) { //nolint:unparam // we want to just do `return raiseErr(...)`\n\t\tif state.Options.Throw.Bool {\n\t\t\treturn false, err\n\t\t}\n\t\tstate.Logger.Warn(err)\n\t\treturn false, nil\n\t}\n\traiseNan := func() (bool, error) {\n\t\treturn raiseErr(fmt.Errorf(\"'%s' is an invalid value for metric '%s', a number or a boolean value is expected\",\n\t\t\tlimitValue(v.String()), m.metric.Name))\n\t}\n\n\tif v == nil {\n\t\treturn raiseErr(fmt.Errorf(\"no value was provided for metric '%s', a number or a boolean value is expected\",\n\t\t\tm.metric.Name))\n\t}\n\tif sobek.IsNull(v) {\n\t\treturn raiseNan()\n\t}\n\n\tvfloat := v.ToFloat()\n\tif vfloat == 0 && v.ToBoolean() {\n\t\tvfloat = 1.0\n\t}\n\n\tif math.IsNaN(vfloat) {\n\t\treturn raiseNan()\n\t}\n\n\tctm := state.Tags.GetCurrentValues()\n\tif err := common.ApplyCustomUserTags(m.vu.Runtime(), &ctm, addTags); err != nil {\n\t\treturn false, fmt.Errorf(\"cannot add tags for the '%s' custom metric: %w\", m.metric.Name, err)","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/metrics/metrics.go#L79-L115","documentation":"Returned by Metric.add when the value argument is nil — i.e. add() was called with no arguments at all (or an explicit undefined). Distinct from the NaN case: here no value was provided whatsoever, so nothing can be recorded for the named custom metric.","triggerScenarios":"Thrown at internal/js/modules/k6/metrics/metrics.go:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Always pass a value: myMetric.add(1, tags) instead of myMetric.add(tags)","Use a default value when a computed metric may be undefined: myMetric.add(x ?? 0)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}