ory/hydra · warning

unable to read from stdin

Error message

unable to read from stdin

What it means

After printing the prompt, AskScannerForConfirmation reads a line from stdin. If ReadString fails (EOF or closed stdin), there is no answer to parse, so it returns false wrapped with this message. Typically happens when stdin is closed or empty in non-interactive runs.

Source

Thrown at oryx/cmdx/user_input.go:47

	}

	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

  1. Provide the answer on stdin, e.g. `echo y | command` or use a heredoc
  2. Use the CLI's non-interactive/assume-yes flag if available instead of relying on stdin
  3. Run the command in an interactive terminal (docker run -i, no </dev/null)
  4. Detect non-interactive environments in scripts and use --force/--yes equivalents

Example fix

// before
$ oryx dangerous-cmd < /dev/null
// after
$ echo y | oryx dangerous-cmd   # or use --yes flag
Defensive patterns

Strategy: fallback

Validate before calling

if fi, err := os.Stdin.Stat(); err != nil || (fi.Mode()&os.ModeCharDevice) == 0 {
    // stdin is not a TTY: feed input or use non-interactive mode
    return fmt.Errorf("stdin is not interactive; provide input or use --yes")
}

Try / catch

ok, err := cmdx.AskForConfirmation("Proceed?")
if err != nil {
    if strings.Contains(err.Error(), "unable to read from stdin") {
        return errStdinUnavailable
    }
    return err
}

Prevention

When it happens

Trigger: Calling AskForConfirmation with stdin at EOF — e.g. `command < /dev/null`, piped-empty input, or CI runs with no TTY — so ReadString('\n') returns io.EOF immediately.

Common situations: Running interactive CLIs from CI/CD without input; forgotten heredoc/echo pipe providing 'y'; Docker containers run without -i.

Related errors


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/ae2e508f124e0821. Report an issue: GitHub.