{"record":{"id":"55a0621152bb501b","repo":"grafana/k6","slug":"metric-s-already-exists-but-with-a-value-type","errorCode":null,"errorMessage":"metric '%s' already exists but with a value type %s, instead of %s","messagePattern":"metric '(.+?)' already exists but with a value type (.+?), instead of (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/registry.go","lineNumber":62,"sourceCode":"\tr.l.Lock()\n\tdefer r.l.Unlock()\n\n\tif !checkName(name) {\n\t\treturn nil, fmt.Errorf(\"Invalid metric name: '%s'. %s\", name, badNameWarning) //nolint:staticcheck\n\t}\n\toldMetric, ok := r.metrics[name]\n\n\tif !ok {\n\t\tm := r.newMetric(name, typ, t...)\n\t\tr.metrics[name] = m\n\t\treturn m, nil\n\t}\n\tif oldMetric.Type != typ {\n\t\treturn nil, fmt.Errorf(\"metric '%s' already exists but with type %s, instead of %s\", name, oldMetric.Type, typ)\n\t}\n\tif len(t) > 0 {\n\t\tif t[0] != oldMetric.Contains {\n\t\t\treturn nil, fmt.Errorf(\"metric '%s' already exists but with a value type %s, instead of %s\",\n\t\t\t\tname, oldMetric.Contains, t[0])\n\t\t}\n\t}\n\treturn oldMetric, nil\n}\n\n// MustNewMetric is like NewMetric, but will panic if there is an error\nfunc (r *Registry) MustNewMetric(name string, typ MetricType, t ...ValueType) *Metric {\n\tm, err := r.NewMetric(name, typ, t...)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn m\n}\n\n// All returns all the registered metrics.\nfunc (r *Registry) All() []*Metric {\n\tr.l.RLock()","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/registry.go#L44-L80","documentation":"Raised by Registry.NewMetric when a metric with the same name was already registered holding a different value type (data vs time), detected while a value type is explicitly requested for the new registration.","triggerScenarios":"Thrown at metrics/registry.go:62 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep the value type consistent across all uses of the metric name","Register the new metric under a different name"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}