{"record":{"id":"bcdc8e92e2de7176","repo":"kovidgoyal/kitty","slug":"failed-to-write-to-stdout-with-error-w","errorCode":null,"errorMessage":"Failed to write to STDOUT with error: %w","messagePattern":"Failed to write to STDOUT with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/clipboard/legacy.go","lineNumber":241,"sourceCode":"\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\n\terr = lp.Run()\n\tif err != nil {\n\t\treturn\n\t}\n\tds := lp.DeathSignalName()\n\tif ds != \"\" {\n\t\tfmt.Println(\"Killed by signal: \", ds)\n\t\tlp.KillIfSignalled()\n\t\treturn\n\t}\n\tif len(clipboard_contents) > 0 {\n\t\t_, err = os.Stdout.Write(clipboard_contents)\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"Failed to write to STDOUT with error: %w\", err)\n\t\t}\n\t}\n\treturn\n}\n","sourceCodeStart":223,"sourceCodeEnd":246,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/clipboard/legacy.go#L223-L246","documentation":"After successfully reading clipboard contents from the terminal, the kitten writes them to STDOUT. If that write fails, this wrapped error is returned. STDOUT is typically a closed or broken pipe.","triggerScenarios":"Running 'kitty +kitten clipboard get' piped into a consumer that exits before reading, e.g. 'kitten +kitten clipboard get | head -c 10' where head quits early, causing EPIPE.","commonSituations":"Piping large clipboard output into head/less that terminates early; redirecting STDOUT to a closed fd; SIGPIPE not suppressed in the pipeline.","solutions":["Ensure the consuming process reads all output or handles SIGPIPE","Use a fully-buffering consumer: kitty +kitten clipboard get > file instead of piping to head","Check the wrapped %w error for EPIPE and treat early-exit consumers as expected"],"exampleFix":"# before\nkitty +kitten clipboard get | head -c 10\n# after\nkitty +kitten clipboard get > /tmp/clip.txt && head -c 10 /tmp/clip.txt","handlingStrategy":"try-catch","validationCode":"// ensure consumer is ready: write to a file instead of a pipe that may close early","typeGuard":null,"tryCatchPattern":"if _, err := os.Stdout.Write(clipboard_contents); err != nil {\n\tif errors.Is(err, syscall.EPIPE) { return nil } // consumer gone, not fatal\n\treturn fmt.Errorf(\"writing stdout: %w\", err)\n}","preventionTips":["Redirect to files instead of piping into short-lived consumers like head","Handle SIGPIPE gracefully in wrappers around the kitten"],"tags":["kitty","clipboard","stdout","broken-pipe"],"backgroundTag":"broken-pipe-on-write","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}