{"record":{"id":"eb35a222d03195ae","repo":"vitessio/vitess","slug":"cannot-marshal-data-v-eb35a2","errorCode":null,"errorMessage":"cannot marshal data: %v","messagePattern":"cannot marshal data: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/api.go","lineNumber":68,"sourceCode":"\t\t}()\n\t\tif err := handlerFunc(w, r); err != nil {\n\t\t\thttpErrorf(w, r, \"%v\", err)\n\t\t}\n\t})\n}\n\nfunc handleCollection(collection string, getFunc func(*http.Request) (any, error)) {\n\thandleAPI(collection+\"/\", func(w http.ResponseWriter, r *http.Request) error {\n\t\t// Get the requested object.\n\t\tobj, err := getFunc(r)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't get %v: %v\", collection, err)\n\t\t}\n\n\t\t// JSON encode response.\n\t\tdata, err := json.MarshalIndent(obj, \"\", \"  \")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot marshal data: %v\", err)\n\t\t}\n\t\tw.Header().Set(\"Content-Type\", jsonContentType)\n\t\tw.Write(data)\n\t\treturn nil\n\t})\n}\n\nfunc getItemPath(url string) string {\n\t// Strip API prefix.\n\tif !strings.HasPrefix(url, apiPrefix) {\n\t\treturn \"\"\n\t}\n\turl = url[len(apiPrefix):]\n\n\t// Strip collection name.\n\tparts := strings.SplitN(url, \"/\", 2)\n\tif len(parts) != 2 {\n\t\treturn \"\"","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/api.go#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"Rare; typically indicates a bug in the data collected by the API (invalid types) rather than user error.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"data, err := doAPICall(path)\nif err != nil && strings.Contains(err, \"cannot marshal data\") {\n    // retry or report the Vitess bug with the offending endpoint\n}","preventionTips":["Report occurrences with the endpoint URL — it's usually a Vitess bug.","Keep Vitess updated to a version where the marshal issue is fixed."],"tags":["vtgate","http-api","json-marshal"],"backgroundTag":"json-serialization-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}