{"record":{"id":"099eabc2e0d62df5","repo":"gofiber/fiber","slug":"sse-finish-comment-w","errorCode":null,"errorMessage":"sse: finish comment: %w","messagePattern":"sse: finish comment: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/sse/event.go","lineNumber":86,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc writeComment(w *bufio.Writer, comment string) error {\n\tcomment = sanitizeComment(comment)\n\tif comment == \"\" {\n\t\tif _, err := w.WriteString(\":\\n\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"sse: write heartbeat: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n\tfor line := range strings.SplitSeq(comment, \"\\n\") {\n\t\tif _, err := fmt.Fprintf(w, \": %s\\n\", line); err != nil {\n\t\t\treturn fmt.Errorf(\"sse: write comment: %w\", err)\n\t\t}\n\t}\n\tif _, err := w.WriteString(\"\\n\"); err != nil {\n\t\treturn fmt.Errorf(\"sse: finish comment: %w\", err)\n\t}\n\treturn nil\n}\n\ntype eventPayload struct {\n\tdata    string\n\thasData bool\n}\n\nfunc eventData(data any, jsonMarshal utils.JSONMarshal) (eventPayload, error) {\n\tswitch value := data.(type) {\n\tcase nil:\n\t\treturn eventPayload{}, nil\n\tcase string:\n\t\treturn eventPayload{data: value, hasData: true}, nil\n\tcase []byte:\n\t\treturn eventPayload{data: string(value), hasData: true}, nil\n\tcase json.RawMessage:","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/sse/event.go#L68-L104","documentation":"Thrown by writeComment when the final '\\n' that terminates a (non-empty) comment cannot be written. This is the last write of the comment routine; failing here means the connection broke during comment emission — same class as 208/210.","triggerScenarios":"Client disconnect, proxy reset, or broken pipe exactly during the trailing-newline write of a comment.","commonSituations":"Connection dying partway through a comment; intermediary closing the stream between writes.","solutions":["Treat as end-of-stream; stop writing and return.","Rely on the stream's closed/error state (stream.Err()) for cleanup decisions."],"exampleFix":"// before\nif err := stream.Comment(note); err != nil { log.Warn(err) /* ignore */ }\n// after\nif err := stream.Comment(note); err != nil { return }","handlingStrategy":"try-catch","validationCode":"// Transport error — not locally preventable. Structure handler to bail on write error.","typeGuard":null,"tryCatchPattern":"if err := stream.Comment(note); err != nil {\n    return // trailing-newline write failed => connection gone\n}","preventionTips":["Treat any write error from the stream as terminal.","Keep the OnClose callback responsible for cleanup driven by stream.Err()."],"tags":["sse","network","write","comment","disconnected"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}