ory/hydra · warning
unable to print to stdout
Error message
unable to print to stdout
What it means
AskScannerForConfirmation prints a yes/no prompt to stdout in a loop. If the Fprintf to stdout fails (broken pipe, closed stdout), the interactive confirmation cannot proceed and the write error is wrapped with this message, returning false.
Source
Thrown at oryx/cmdx/user_input.go:42
}
ok, err := AskScannerForConfirmation(s, bufio.NewReader(stdin), stdout)
if err != nil {
Must(err, "Unable to confirm: %s", err)
}
return ok
}
func AskScannerForConfirmation(s string, reader *bufio.Reader, stdout io.Writer) (bool, error) {
if stdout == nil {
stdout = os.Stdout
}
for {
_, err := fmt.Fprintf(stdout, "%s [y/n]: ", s)
if err != nil {
return false, errors.Wrap(err, "unable to print to stdout")
}
response, err := reader.ReadString('\n')
if err != nil {
return false, errors.Wrap(err, "unable to read from stdin")
}
response = strings.ToLower(strings.TrimSpace(response))
if response == "y" || response == "yes" {
return true, nil
} else if response == "n" || response == "no" {
return false, nil
}
}
}
View on GitHub (pinned to 4174065ffb)
Solutions
- Ensure stdout is writable before prompting — run the command with a valid terminal or redirect stdout to a file
- Avoid piping the interactive command into tools that exit early (e.g. `| head`) — use `--yes`/non-interactive flags if available
- Check for a non-interactive mode or pre-answer flag in the CLI to skip confirmation entirely
- Handle the returned error in your wrapper and fall back to explicit confirmation logic
Example fix
// before $ oryx dangerous-cmd | head -1 # stdout closes -> prompt write fails // after $ oryx dangerous-cmd --yes # or run without the broken pipe
Defensive patterns
Strategy: fallback
Validate before calling
if fi, err := os.Stdout.Stat(); err != nil || fi == nil {
return fmt.Errorf("stdout unavailable; use a non-interactive mode")
} Try / catch
ok, err := cmdx.AskForConfirmation("Proceed?")
if err != nil {
log.WithError(err).Warn("cannot prompt; aborting interactive confirmation")
return errInteractiveUnavailable
} Prevention
- Do not pipe interactive commands into consumers that close stdout early (e.g. `| head`)
- Provide non-interactive flags (--yes/--force) in automation
- Run CLI prompts only with a writable stdout (TTY or file redirect)
- Catch this error in wrappers and surface a clear 'interactive mode required' message
When it happens
Trigger: Calling AskForConfirmation (via AskScannerForConfirmation) in an environment where stdout is closed or broken — e.g. piping output to a closed consumer, running headless/CI with stdout redirected to a dead descriptor.
Common situations: Running interactive CLIs in CI where stdout is `head`-truncated (SIGPIPE); scripts closing fd 1; containers without a working TTY/stdout.
Related errors
- unable to read from stdin
- failed to write json output
- command expects one argument which is the path to the output
- A DSN is required as a positional argument when not passing
- Janitor requires at least one of --tokens, --requests or --g
AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03).
Data as JSON: /api/errors/ab770041613032fa.
Report an issue: GitHub.