{"record":{"id":"ab770041613032fa","repo":"ory/hydra","slug":"unable-to-print-to-stdout","errorCode":null,"errorMessage":"unable to print to stdout","messagePattern":"unable to print to stdout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"oryx/cmdx/user_input.go","lineNumber":42,"sourceCode":"\t}\n\n\tok, err := AskScannerForConfirmation(s, bufio.NewReader(stdin), stdout)\n\tif err != nil {\n\t\tMust(err, \"Unable to confirm: %s\", err)\n\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":24,"sourceCodeEnd":58,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/cmdx/user_input.go#L24-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running interactive CLIs in CI where stdout is `head`-truncated (SIGPIPE); scripts closing fd 1; containers without a working TTY/stdout.","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"],"exampleFix":"// before\n$ oryx dangerous-cmd | head -1   # stdout closes -> prompt write fails\n// after\n$ oryx dangerous-cmd --yes       # or run without the broken pipe","handlingStrategy":"fallback","validationCode":"if fi, err := os.Stdout.Stat(); err != nil || fi == nil {\n    return fmt.Errorf(\"stdout unavailable; use a non-interactive mode\")\n}","typeGuard":null,"tryCatchPattern":"ok, err := cmdx.AskForConfirmation(\"Proceed?\")\nif err != nil {\n    log.WithError(err).Warn(\"cannot prompt; aborting interactive confirmation\")\n    return errInteractiveUnavailable\n}","preventionTips":["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"],"tags":["io","cli","stdout","interactive"],"backgroundTag":"broken-pipe-stdout","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"}