thanos-io/thanos · error
decode result into ValueTypeMatrix
Error message
decode result into ValueTypeMatrix
What it means
After the envelope decodes, QueryRange sees data.resultType == "matrix" and unmarshals data.result into prometheus/common's model.Matrix. This error wraps a failure to decode the raw result JSON into that type — the samples/series inside data.result do not match the expected matrix JSON structure (arrays of {metric, values} objects).
Solutions
- Log m.Data.Result (raw JSON) at the call site to inspect the actual sample structure.
- Confirm the server is genuine Prometheus/Thanos and check its version; upgrade if a known result-encoding bug exists.
- Check for response-rewriting middleware or caches in the path and bypass them to test directly.
- Validate the query itself does not hit a federated/gateway layer that reformats results.
Defensive patterns
Strategy: try-catch
Try / catch
if err != nil && strings.Contains(err.Error(), "decode result into ValueTypeMatrix") {
// capture raw result for debugging; suspect server/middleware corruption
} Prevention
- Use stock Prometheus/Thanos servers; avoid response-rewriting middleware
- Pin and test server versions in CI
- Log raw result payloads on failure for post-mortem
When it happens
Trigger: QueryRange (via Exec) receives a 200 response whose resultType is "matrix" but whose result payload cannot decode into model.Matrix — e.g. values arrays containing non-numeric strings, malformed sample pairs, or a nonstandard result emitted by a proxy/modified server.
Common situations: A third-party or older server claiming resultType matrix but emitting differently shaped samples; a caching proxy serving a corrupted/cached body; custom Prometheus forks or response-rewriting middleware.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- unmarshal response
- unmarshal query instant response
- unmarshal query range response
- unmarshal build info API response
- unmarshal marker JSON
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/77c04d4de500d770.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/promclient/promclient.go:589
} `json:"data"`
Error string `json:"error,omitempty"`
ErrorType string `json:"errorType,omitempty"`
// Extra fields supported by Thanos Querier.
Warnings []string `json:"warnings"`
}
if err = json.Unmarshal(body, &m); err != nil {
return nil, nil, nil, errors.Wrap(err, "unmarshal query range response")
}
var matrixResult model.Matrix
// Decode the Result depending on the ResultType
switch m.Data.ResultType {
case string(parser.ValueTypeMatrix):
if err = json.Unmarshal(m.Data.Result, &matrixResult); err != nil {
return nil, nil, nil, errors.Wrap(err, "decode result into ValueTypeMatrix")
}
default:
if m.Warnings != nil {
return nil, nil, nil, errors.Errorf("error: %s, type: %s, warning: %s", m.Error, m.ErrorType, strings.Join(m.Warnings, ", "))
}
if m.Error != "" {
return nil, nil, nil, errors.Errorf("error: %s, type: %s", m.Error, m.ErrorType)
}
return nil, nil, nil, errors.Errorf("received status code: 200, unknown response type: '%q'", m.Data.ResultType)
}
return matrixResult, m.Warnings, m.Data.Explanation, nil
}
// Scalar response consists of array with mixed types so it needs to be
// unmarshaled separately.
func convertScalarJSONToVector(scalarJSONResult json.RawMessage) (model.Vector, error) {
var (View on GitHub (pinned to 35b8b99117)