{"record":{"id":"ae2e508f124e0821","repo":"ory/hydra","slug":"unable-to-read-from-stdin","errorCode":null,"errorMessage":"unable to read from stdin","messagePattern":"unable to read from stdin","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"oryx/cmdx/user_input.go","lineNumber":47,"sourceCode":"\t}\n\n\treturn ok\n}\n\nfunc AskScannerForConfirmation(s string, reader *bufio.Reader, stdout io.Writer) (bool, error) {\n\tif stdout == nil {\n\t\tstdout = os.Stdout\n\t}\n\n\tfor {\n\t\t_, err := fmt.Fprintf(stdout, \"%s [y/n]: \", s)\n\t\tif err != nil {\n\t\t\treturn false, errors.Wrap(err, \"unable to print to stdout\")\n\t\t}\n\n\t\tresponse, err := reader.ReadString('\\n')\n\t\tif err != nil {\n\t\t\treturn false, errors.Wrap(err, \"unable to read from stdin\")\n\t\t}\n\n\t\tresponse = strings.ToLower(strings.TrimSpace(response))\n\t\tif response == \"y\" || response == \"yes\" {\n\t\t\treturn true, nil\n\t\t} else if response == \"n\" || response == \"no\" {\n\t\t\treturn false, nil\n\t\t}\n\t}\n}\n","sourceCodeStart":29,"sourceCodeEnd":58,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/cmdx/user_input.go#L29-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running interactive CLIs from CI/CD without input; forgotten heredoc/echo pipe providing 'y'; Docker containers run without -i.","solutions":["Provide the answer on stdin, e.g. `echo y | command` or use a heredoc","Use the CLI's non-interactive/assume-yes flag if available instead of relying on stdin","Run the command in an interactive terminal (docker run -i, no </dev/null)","Detect non-interactive environments in scripts and use --force/--yes equivalents"],"exampleFix":"// before\n$ oryx dangerous-cmd < /dev/null\n// after\n$ echo y | oryx dangerous-cmd   # or use --yes flag","handlingStrategy":"fallback","validationCode":"if fi, err := os.Stdin.Stat(); err != nil || (fi.Mode()&os.ModeCharDevice) == 0 {\n    // stdin is not a TTY: feed input or use non-interactive mode\n    return fmt.Errorf(\"stdin is not interactive; provide input or use --yes\")\n}","typeGuard":null,"tryCatchPattern":"ok, err := cmdx.AskForConfirmation(\"Proceed?\")\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to read from stdin\") {\n        return errStdinUnavailable\n    }\n    return err\n}","preventionTips":["Pipe answers explicitly: echo y | command, or use a heredoc","Use --yes/--force flags in CI and scripts instead of interactive prompts","Run docker commands with -i when stdin input is expected","Detect non-TTY stdin early and switch to non-interactive flows"],"tags":["io","cli","stdin","interactive"],"backgroundTag":"stdin-eof-interactive-prompt","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}