{"record":{"id":"e50cf48ad16a2b87","repo":"weaviate/weaviate","slug":"failed-to-marshal-response-v-error-v","errorCode":null,"errorMessage":"failed to marshal response: %+v, error: %v","messagePattern":"failed to marshal response: %\\+v, error: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"adapters/handlers/rest/clusterapi/indices_replicas.go","lineNumber":313,"sourceCode":"\n\t\tvar resp interface{}\n\n\t\tswitch cmd {\n\t\tcase \"commit\":\n\t\t\tresp = i.replicator.CommitReplication(r.Context(), index, shard, requestID)\n\t\tcase \"abort\":\n\t\t\tresp = i.replicator.AbortReplication(r.Context(), index, shard, requestID)\n\t\tdefault:\n\t\t\thttp.Error(w, fmt.Sprintf(\"unrecognized command: %s\", cmd), http.StatusNotImplemented)\n\t\t\treturn\n\t\t}\n\t\tif resp == nil { // could not find request with specified id\n\t\t\thttp.Error(w, \"request not found\", http.StatusNotFound)\n\t\t\treturn\n\t\t}\n\t\tb, err := json.Marshal(resp)\n\t\tif err != nil {\n\t\t\thttp.Error(w, fmt.Sprintf(\"failed to marshal response: %+v, error: %v\", resp, err),\n\t\t\t\thttp.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\tw.Write(b)\n\t})\n}\n\nfunc (i *replicatedIndices) postObject() http.Handler {\n\treturn http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\targs := regxObjects.FindStringSubmatch(r.URL.Path)\n\t\tif len(args) != 3 {\n\t\t\thttp.Error(w, \"invalid URI\", http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\n\t\trequestID := r.URL.Query().Get(replica.RequestKey)\n\t\tif requestID == \"\" {\n\t\t\thttp.Error(w, \"request_id not provided\", http.StatusBadRequest)","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/handlers/rest/clusterapi/indices_replicas.go#L295-L331","documentation":"The handler marshals the replicator's response to JSON before writing it; a marshal failure (essentially impossible for the supported response types) yields HTTP 500 with the response value and the underlying error embedded in the body.","triggerScenarios":"A replicator.CommitReplication/AbortReplication implementation returning a value json.Marshal cannot encode (e.g. a type containing a channel, func, or cyclic reference) — theoretically a code bug rather than caller error.","commonSituations":"After modifying the replicator to return a custom response type that is not JSON-serializable, or a dependency upgrade introducing an incompatible response type.","solutions":["Inspect the error in the response body to identify the offending type","Ensure the replicator response type contains only JSON-serializable fields (add json tags, remove func/channel fields)","File/fix a bug in the replicator if a stock response type fails to marshal"],"exampleFix":"// before\ntype resp struct { Done chan bool }\n// after\ntype resp struct { Done bool `json:\"done\"` }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := doReplicationCall(url)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal response\") {\n        // server-side serialization bug: capture body and report\n        return fmt.Errorf(\"replicator returned unserializable response: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep replicator response types JSON-serializable (no chan/func fields)","Add json struct tags to all response structs","Add a unit test that json.Marshals every replicator response type"],"tags":["http","clusterapi","json","internal-server-error"],"backgroundTag":"json-marshal-failed","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}