{"record":{"id":"46271eb93bb32c0b","repo":"netbirdio/netbird","slug":"failed-to-marshal-response","errorCode":null,"errorMessage":"failed to marshal response","messagePattern":"failed to marshal response","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"upload-server/server/server.go","lineNumber":99,"sourceCode":"\t\thttp.Error(w, \"method not allowed\", http.StatusMethodNotAllowed)\n\t\treturn false\n\t}\n\n\tif r.Header.Get(types.ClientHeader) != types.ClientHeaderValue {\n\t\thttp.Error(w, \"unauthorized\", http.StatusUnauthorized)\n\t\treturn false\n\t}\n\treturn true\n}\nfunc respondGetRequest(w http.ResponseWriter, uploadURL string, objectKey string) {\n\tresponse := types.GetURLResponse{\n\t\tURL: uploadURL,\n\t\tKey: objectKey,\n\t}\n\n\trdata, err := json.Marshal(response)\n\tif err != nil {\n\t\thttp.Error(w, \"failed to marshal response\", http.StatusInternalServerError)\n\t\tlog.Errorf(\"Marshal error: %v\", err)\n\t\treturn\n\t}\n\n\tw.WriteHeader(http.StatusOK)\n\t_, err = w.Write(rdata)\n\tif err != nil {\n\t\tlog.Errorf(\"Write error: %v\", err)\n\t}\n}\n","sourceCodeStart":81,"sourceCodeEnd":110,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/upload-server/server/server.go#L81-L110","documentation":"HTTP 500 from respondGetRequest when json.Marshal of the GetURLResponse struct fails. The struct holds only two exported string fields (URL, Key), which json.Marshal cannot fail on today, so seeing this error implies a server regression: types.GetURLResponse gained an unmarshalable field (chan, func, or reference cycle).","triggerScenarios":"Only reachable if GetURLResponse is extended with a field json.Marshal rejects or a self-referential type; with the current two-string struct the branch is dead code.","commonSituations":"Practically never in production; would surface immediately after a change to upload-server/types/upload.go, typically in CI or a canary deployment.","solutions":["Treat it as a server code defect: inspect recent changes to types.GetURLResponse for chan/func/self-referential fields","Add a unit test asserting json.Marshal(GetURLResponse{}) succeeds so the regression is caught before deploy","Client side: report the 500; no request change will avoid it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"On 500 'failed to marshal response', retry the GET once (transient code path is theoretically impossible), then report it upstream as a server regression in types.GetURLResponse.","preventionTips":["Keep a unit test asserting json.Marshal(types.GetURLResponse{}) succeeds","Never add chan/func or self-referential fields to response DTOs"],"tags":["json","serialization","go","dead-code"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}