{"record":{"id":"f9b5edb2a3b6d613","repo":"geektutu/7days-golang","slug":"err-error-f9b5ed","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"gee-web/day2-context/gee/context.go","lineNumber":59,"sourceCode":"\tc.Writer.WriteHeader(code)\n}\n\nfunc (c *Context) SetHeader(key string, value string) {\n\tc.Writer.Header().Set(key, value)\n}\n\nfunc (c *Context) String(code int, format string, values ...interface{}) {\n\tc.SetHeader(\"Content-Type\", \"text/plain\")\n\tc.Status(code)\n\tc.Writer.Write([]byte(fmt.Sprintf(format, values...)))\n}\n\nfunc (c *Context) JSON(code int, obj interface{}) {\n\tc.SetHeader(\"Content-Type\", \"application/json\")\n\tc.Status(code)\n\tencoder := json.NewEncoder(c.Writer)\n\tif err := encoder.Encode(obj); err != nil {\n\t\thttp.Error(c.Writer, err.Error(), 500)\n\t}\n}\n\nfunc (c *Context) Data(code int, data []byte) {\n\tc.Status(code)\n\tc.Writer.Write(data)\n}\n\nfunc (c *Context) HTML(code int, html string) {\n\tc.SetHeader(\"Content-Type\", \"text/html\")\n\tc.Status(code)\n\tc.Writer.Write([]byte(html))\n}\n","sourceCodeStart":41,"sourceCodeEnd":73,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-web/day2-context/gee/context.go#L41-L73","documentation":"Serialization failure handler in Context.JSON: json.Encoder.Encode failed to marshal the response object (unsupported type, channel/func field, unexported-only struct, cyclic reference), so a plain-text 500 with the encoder error is written instead of JSON. It fires at response-writing time, not request-parsing time.","triggerScenarios":"Thrown at gee-web/day2-context/gee/context.go:59 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the response object is JSON-serializable: no channels, funcs, or cyclic references; export fields you want encoded.","Pre-marshal in tests with json.Marshal to catch unsupported types before serving.","Return a structured JSON error object instead of the default http.Error text."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}