kovidgoyal/kitty · error

Failed to write to STDOUT with error: %w

Error message

Failed to write to STDOUT with error: %w

What it means

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.

Source

Thrown at kittens/clipboard/legacy.go:241

			}
		}
		return nil
	}

	err = lp.Run()
	if err != nil {
		return
	}
	ds := lp.DeathSignalName()
	if ds != "" {
		fmt.Println("Killed by signal: ", ds)
		lp.KillIfSignalled()
		return
	}
	if len(clipboard_contents) > 0 {
		_, err = os.Stdout.Write(clipboard_contents)
		if err != nil {
			err = fmt.Errorf("Failed to write to STDOUT with error: %w", err)
		}
	}
	return
}

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Ensure the consuming process reads all output or handles SIGPIPE
  2. Use a fully-buffering consumer: kitty +kitten clipboard get > file instead of piping to head
  3. Check the wrapped %w error for EPIPE and treat early-exit consumers as expected

Example fix

# before
kitty +kitten clipboard get | head -c 10
# after
kitty +kitten clipboard get > /tmp/clip.txt && head -c 10 /tmp/clip.txt
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure consumer is ready: write to a file instead of a pipe that may close early

Try / catch

if _, err := os.Stdout.Write(clipboard_contents); err != nil {
	if errors.Is(err, syscall.EPIPE) { return nil } // consumer gone, not fatal
	return fmt.Errorf("writing stdout: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: Piping large clipboard output into head/less that terminates early; redirecting STDOUT to a closed fd; SIGPIPE not suppressed in the pipeline.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/bcdc8e92e2de7176. Report an issue: GitHub.