{"record":{"id":"689b317e42856b14","repo":"charmbracelet/glow","slug":"unable-to-write-to-writer-w","errorCode":null,"errorMessage":"unable to write to writer: %w","messagePattern":"unable to write to writer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":341,"sourceCode":"\t\tif err != nil || len(fields) == 0 {\n\t\t\treturn fmt.Errorf(\"unable to parse PAGER command: %s\", pagerCmd)\n\t\t}\n\t\tc := exec.Command(fields[0], fields[1:]...) //nolint:gosec\n\t\tc.Stdin = strings.NewReader(out)\n\t\tc.Stdout = os.Stdout\n\t\tif err := c.Run(); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to run command: %w\", err)\n\t\t}\n\t\treturn nil\n\tcase tui || cmd.Flags().Changed(\"tui\"):\n\t\tpath := \"\"\n\t\tif !isURL(src.URL) {\n\t\t\tpath = src.URL\n\t\t}\n\t\treturn runTUI(path, content)\n\tdefault:\n\t\tif _, err = fmt.Fprint(w, out); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to write to writer: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n}\n\nfunc runTUI(path string, content string) error {\n\t// Read environment to get debugging stuff\n\tcfg, err := env.ParseAs[ui.Config]()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error parsing config: %v\", err)\n\t}\n\n\t// use style set in env, or auto if unset\n\tif err := validateStyle(cfg.GlamourStyle); err != nil {\n\t\tcfg.GlamourStyle = style\n\t}\n\n\tcfg.Path = path","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/main.go#L323-L359","documentation":"The default display path writes the rendered output with fmt.Fprint(w, out). Failure means writing to the destination writer failed - most commonly a broken pipe (EPIPE) when the downstream consumer exits early, e.g. glow README.md | head. It can also mean the output target is unwritable: disk full (ENOSPC) or a redirected file on a dead mount.","triggerScenarios":"Piping glow into head/less/grep -m1 that exits before glow finishes writing (EPIPE); stdout redirected to a file on a full filesystem; stdout closed or revoked mid-write.","commonSituations":"Piping rendered output into short-lived readers, CI log capture with size caps, disk-full conditions when redirecting to files.","solutions":["If piping into head-like tools, treat EPIPE as benign - it is expected, not a glow bug","Check disk space when redirecting to a file: df -h .","Write to a file first and inspect the tail: glow README.md > out.txt","Use less as the consumer (glow -p) instead of piping to head"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isEPIPE(err error) bool { return errors.Is(err, syscall.EPIPE) }","tryCatchPattern":"if _, err := fmt.Fprint(w, out); err != nil {\n\tif errors.Is(err, syscall.EPIPE) {\n\t\treturn nil // downstream reader closed early: not a real failure\n\t}\n\treturn fmt.Errorf(\"unable to write to writer: %w\", err)\n}","preventionTips":["Treat EPIPE as success when output feeds short-lived readers like head","Buffer output before writing to fragile pipes","Monitor disk space when redirecting output to files"],"tags":["io","stdout","pipe"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}