{"record":{"id":"6aed7d15a4820cee","repo":"charmbracelet/gum","slug":"unable-to-write-output-w","errorCode":null,"errorMessage":"unable to write output: %w","messagePattern":"unable to write output: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"format/command.go","lineNumber":46,"sourceCode":"\t\tinput, _ = stdin.Read(stdin.StripANSI(o.StripANSI))\n\t}\n\n\tswitch o.Type {\n\tcase \"code\":\n\t\toutput, err = code(input, o.Language)\n\tcase \"emoji\":\n\t\toutput, err = emoji(input)\n\tcase \"template\":\n\t\toutput, err = template(input)\n\tdefault:\n\t\toutput, err = markdown(input, o.Theme)\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif _, err := fmt.Fprint(tty.Writer(), output); err != nil {\n\t\treturn fmt.Errorf(\"unable to write output: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":28,"sourceCodeEnd":50,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/format/command.go#L28-L50","documentation":"gum format renders markdown/code/emoji/text and then writes the result with `fmt.Fprint(tty.Writer(), output)`. If that final write fails, Run wraps the error as `unable to write output: %w`. The rendering succeeded; only the emission to the TTY writer failed.","triggerScenarios":"The writer returned by the TTY detection (`tty.Writer()`) points at a closed or broken descriptor — e.g. stdout piped to a process that exited (EPIPE), a full disk, or an invalid output target.","commonSituations":"`gum format ... | head -1` closing the pipe early (broken pipe); redirecting output to a file on a full filesystem; output device removed/disconnected mid-run.","solutions":["Check whether the consumer of the pipe exited early (EPIPE); avoid `head`/`grep -q` short-circuits or ignore SIGPIPE.","Verify disk space and write permissions on the redirect target.","Run `gum format` writing to a healthy terminal or a writable file.","Inspect the wrapped error (`EPIPE`, `ENOSPC`) to pinpoint the cause."],"exampleFix":"// before\ngum format -t markdown \"$doc\" | head -1 // consumer exits -> broken pipe\n// after\ngum format -t markdown \"$doc\" | sed -n '1p;q' # or capture full output first: out=$(gum format -t markdown \"$doc\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if ! out=$(gum format -t markdown \"$doc\"); then\n  echo \"write failed: $out (EPIPE? ENOSPC?)\" >&2\nfi","preventionTips":["Avoid pipe consumers that exit early (head) or tolerate SIGPIPE.","Check disk space before writing large formatted output to files.","Capture output into a variable instead of chaining fragile pipes.","Inspect the wrapped errno (EPIPE/ENOSPC/EBADF) to diagnose quickly."],"tags":["go","cli","io","broken-pipe"],"backgroundTag":"broken-pipe","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}