{"record":{"id":"d6d759dbd5c116b0","repo":"thanos-io/thanos","slug":"unmarshaling-scalar-time-from-v","errorCode":null,"errorMessage":"unmarshaling scalar time from %v","messagePattern":"unmarshaling scalar time from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":621,"sourceCode":"\n// Scalar response consists of array with mixed types so it needs to be\n// unmarshaled separately.\nfunc 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]\")","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L603-L639","documentation":"The first element of the scalar tuple must decode into prometheus/common's model.Time (a millisecond Unix timestamp number). This error wraps json.Unmarshal failing on resultPointSlice[0] — the timestamp element is not a number (e.g. a string, null, or object).","triggerScenarios":"QueryInstant/TestRule_UnmarshalScalarResponse receives a scalar result whose tuple[0] is not JSON-parseable into model.Time: string timestamps, null, or nested values.","commonSituations":"Custom or buggy server emitting timestamps as ISO strings instead of epoch milliseconds; hand-written test fixtures with wrong types; middleware converting numbers to strings.","solutions":["Ensure the server emits the timestamp as a JSON number in Unix milliseconds.","Log resultPointSlice[0] to see the offending value.","Fix test fixtures to use numeric epoch-millisecond timestamps.","If the upstream genuinely sends string timestamps, convert on the server side rather than patching the client."],"exampleFix":"// before\n\"result\": [\"2024-03-09T12:00:00Z\", \"42\"]\n// after\n\"result\": [1710000000000, \"42\"]","handlingStrategy":"validation","validationCode":"// fixture check: tuple[0] must be a JSON number (unix ms)\nvar ts json.Number\nif err := json.Unmarshal(raw[0], &ts); err != nil {\n    return fmt.Errorf(\"scalar timestamp must be numeric unix ms, got %s\", raw[0])\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unmarshaling scalar time\") {\n    // timestamp element wrong type; log it and fix the source\n}","preventionTips":["Emit timestamps as epoch milliseconds, never ISO strings or null","Generate test fixtures from real Prometheus responses","Check server implementation for custom timestamp formatting"],"tags":["prometheus","scalar","timestamp","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"}