vitessio/vitess · error
cannot marshal data: %v
Error message
cannot marshal data: %v
What it means
In the same vtgate HTTP API handler, after successfully fetching the object, json.MarshalIndent of the response fails and returns `cannot marshal data: <err>`. This is an internal serialization failure — the fetched object could not be encoded to JSON.
Source
Thrown at go/vt/vtgate/api.go:68
}()
if err := handlerFunc(w, r); err != nil {
httpErrorf(w, r, "%v", err)
}
})
}
func handleCollection(collection string, getFunc func(*http.Request) (any, error)) {
handleAPI(collection+"/", func(w http.ResponseWriter, r *http.Request) error {
// Get the requested object.
obj, err := getFunc(r)
if err != nil {
return fmt.Errorf("can't get %v: %v", collection, err)
}
// JSON encode response.
data, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return fmt.Errorf("cannot marshal data: %v", err)
}
w.Header().Set("Content-Type", jsonContentType)
w.Write(data)
return nil
})
}
func getItemPath(url string) string {
// Strip API prefix.
if !strings.HasPrefix(url, apiPrefix) {
return ""
}
url = url[len(apiPrefix):]
// Strip collection name.
parts := strings.SplitN(url, "/", 2)
if len(parts) != 2 {
return ""View on GitHub (pinned to 01a25a7d17)
Solutions
- Inspect the wrapped marshal error to identify the offending field/type.
- Report/fix the data type producing unmarshalable values in the API handler.
- Retry the request after upgrading Vitess if it is a known bug.
Defensive patterns
Strategy: try-catch
Try / catch
data, err := doAPICall(path)
if err != nil && strings.Contains(err, "cannot marshal data") {
// retry or report the Vitess bug with the offending endpoint
} Prevention
- Report occurrences with the endpoint URL — it's usually a Vitess bug.
- Keep Vitess updated to a version where the marshal issue is fixed.
When it happens
Trigger: A vtgate debug API object contains a value that json cannot encode (e.g. unsupported type, NaN, or marshal error inside the collected data) while serving /api/<collection>/ requests.
Common situations: Rare; typically indicates a bug in the data collected by the API (invalid types) rather than user error.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- can't get %v: %v
- invalid health-check path: %q expected path: / or /cell/<ce
- cells can only be listed, not retrieved
- a POST request needs a keyspace in the URL
- a POST request must specify action
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/eb35a222d03195ae.
Report an issue: GitHub.