{"record":{"id":"f737ebda67d86b8a","repo":"thanos-io/thanos","slug":"unmarshaling-scalar-value-from-v","errorCode":null,"errorMessage":"unmarshaling scalar value from %v","messagePattern":"unmarshaling scalar value from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":624,"sourceCode":"func convertScalarJSONToVector(scalarJSONResult json.RawMessage) (model.Vector, error) {\n\tvar (\n\t\t// Do not specify exact length of the expected slice since JSON unmarshaling\n\t\t// would make the length fit the size and we won't be able to check the length afterwards.\n\t\tresultPointSlice []json.RawMessage\n\t\tresultTime       model.Time\n\t\tresultValue      model.SampleValue\n\t)\n\tif err := json.Unmarshal(scalarJSONResult, &resultPointSlice); err != nil {\n\t\treturn nil, err\n\t}\n\tif len(resultPointSlice) != 2 {\n\t\treturn nil, errors.Errorf(\"invalid scalar result format %v, expected timestamp -> value tuple\", resultPointSlice)\n\t}\n\tif err := json.Unmarshal(resultPointSlice[0], &resultTime); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"unmarshaling scalar time from %v\", resultPointSlice)\n\t}\n\tif err := json.Unmarshal(resultPointSlice[1], &resultValue); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"unmarshaling scalar value from %v\", resultPointSlice)\n\t}\n\treturn model.Vector{&model.Sample{\n\t\tMetric:    model.Metric{},\n\t\tValue:     resultValue,\n\t\tTimestamp: resultTime}}, nil\n}\n\n// AlertmanagerAlerts returns alerts from Alertmanager.\nfunc (c *Client) AlertmanagerAlerts(ctx context.Context, base *url.URL) ([]*model.Alert, error) {\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/alerts\")\n\n\tlevel.Debug(c.logger).Log(\"msg\", \"querying instant\", \"url\", u.String())\n\n\tspan, ctx := tracing.StartSpan(ctx, \"/alertmanager_alerts HTTP[client]\")\n\tdefer span.Finish()\n\n\tbody, _, err := c.req2xx(ctx, &u, http.MethodGet, nil)","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L606-L642","documentation":"The second element of the scalar tuple must decode into model.SampleValue (a float64). This error wraps json.Unmarshal failing on resultPointSlice[1] — the value element is not a number-compatible JSON value (e.g. a non-numeric string, null, or an object).","triggerScenarios":"QueryInstant/TestRule_UnmarshalScalarResponse receives a scalar result whose tuple[1] cannot parse as a float: strings like \"NaN\" outside quotes handling, \"n/a\", units embedded in values, or null.","commonSituations":"Nonstandard backends returning formatted values (\"1.2k\", \"12%\"), null for missing data, or test fixtures with wrong value types.","solutions":["Ensure the value element is a numeric JSON value or a string that parses as float (Prometheus emits values as strings like \"42\"; model.SampleValue accepts those).","Log resultPointSlice[1] to inspect the actual payload.","Fix the emitting server/fixture to return Prometheus-style numeric strings.","Replace null placeholders with numeric values (0) if the source cannot produce a real sample."],"exampleFix":"// before\n\"result\": [1710000000000, \"n/a\"]\n// after\n\"result\": [1710000000000, \"42\"]","handlingStrategy":"validation","validationCode":"// fixture check: tuple[1] must parse as float\nvar val model.SampleValue\nif err := json.Unmarshal(raw[1], &val); err != nil {\n    return fmt.Errorf(\"scalar value must be numeric, got %s\", raw[1])\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unmarshaling scalar value\") {\n    // value element wrong type; log raw payload and fix emitter\n}","preventionTips":["Emit values as numbers or numeric strings (\"42\"), never \"n/a\"/units/null","Validate fixtures with promtool or against live server output","Handle NaN/Inf using Prometheus JSON conventions, not custom strings"],"tags":["prometheus","scalar","value","unmarshal"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}