charmbracelet/glow · error
unable to write to writer: %w
Error message
unable to write to writer: %w
What it means
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.
Source
Thrown at main.go:341
if err != nil || len(fields) == 0 {
return fmt.Errorf("unable to parse PAGER command: %s", pagerCmd)
}
c := exec.Command(fields[0], fields[1:]...) //nolint:gosec
c.Stdin = strings.NewReader(out)
c.Stdout = os.Stdout
if err := c.Run(); err != nil {
return fmt.Errorf("unable to run command: %w", err)
}
return nil
case tui || cmd.Flags().Changed("tui"):
path := ""
if !isURL(src.URL) {
path = src.URL
}
return runTUI(path, content)
default:
if _, err = fmt.Fprint(w, out); err != nil {
return fmt.Errorf("unable to write to writer: %w", err)
}
return nil
}
}
func runTUI(path string, content string) error {
// Read environment to get debugging stuff
cfg, err := env.ParseAs[ui.Config]()
if err != nil {
return fmt.Errorf("error parsing config: %v", err)
}
// use style set in env, or auto if unset
if err := validateStyle(cfg.GlamourStyle); err != nil {
cfg.GlamourStyle = style
}
cfg.Path = pathView on GitHub (pinned to e3970c813d)
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
Defensive patterns
Strategy: try-catch
Type guard
func isEPIPE(err error) bool { return errors.Is(err, syscall.EPIPE) } Try / catch
if _, err := fmt.Fprint(w, out); err != nil {
if errors.Is(err, syscall.EPIPE) {
return nil // downstream reader closed early: not a real failure
}
return fmt.Errorf("unable to write to writer: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Piping rendered output into short-lived readers, CI log capture with size caps, disk-full conditions when redirecting to files.
Related errors
- unable to write config file: %w
- unable to read http response body: %w
- unable to read http response body: %w
- unable to open file: %w
- unable to read from reader: %w
AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15).
Data as JSON: /api/errors/689b317e42856b14.
Report an issue: GitHub.