{"record":{"id":"6d65bae4a061932c","repo":"amir20/dozzle","slug":"failed-to-read-password-w","errorCode":null,"errorMessage":"failed to read password: %w","messagePattern":"failed to read password: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/support/cli/generate_command.go","lineNumber":71,"sourceCode":"\tif _, err := os.Stdout.Write(buffer.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"failed to write to stdout: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// readPassword reads a password from stdin. Prompts are written to stderr so\n// they don't pollute stdout (which is commonly redirected to users.yml). When\n// stdin is a terminal the input is read without echo; otherwise a single line\n// is read (supports piping, e.g. `echo secret | dozzle generate ...`).\nfunc readPassword() (string, error) {\n\tfd := int(os.Stdin.Fd())\n\tif term.IsTerminal(fd) {\n\t\tfmt.Fprint(os.Stderr, \"Password: \")\n\t\tbytePassword, err := term.ReadPassword(fd)\n\t\tfmt.Fprintln(os.Stderr)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to read password: %w\", err)\n\t\t}\n\t\treturn strings.TrimRight(string(bytePassword), \"\\r\\n\"), nil\n\t}\n\n\treader := bufio.NewReader(os.Stdin)\n\tline, err := reader.ReadString('\\n')\n\tif err != nil && line == \"\" {\n\t\treturn \"\", fmt.Errorf(\"failed to read password from stdin: %w\", err)\n\t}\n\treturn strings.TrimRight(line, \"\\r\\n\"), nil\n}\n","sourceCodeStart":53,"sourceCodeEnd":83,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/support/cli/generate_command.go#L53-L83","documentation":"`readPassword` uses `term.ReadPassword` when stdin is a terminal. If the terminal read syscall fails, the error is wrapped as 'failed to read password'. This guards the interactive prompt path of `dozzle generate`.","triggerScenarios":"Running `dozzle generate` in an environment where stdin is a terminal but the read fails: stdin closed or not readable (fd reopened/invalid), terminal I/O errors, or fd 0 replaced by a non-readable device.","commonSituations":"Running inside wrappers/IDE terminals with broken TTY handling; containers with a TTY allocated but stdin detached; sandboxed environments restricting terminal ioctls.","solutions":["Re-run in a normal interactive terminal with a working TTY","If non-interactive, pipe the password via stdin instead: `echo 'pass' | dozzle generate`","Check terminal emulator / ssh session health and retry"],"exampleFix":"// before\nssh host 'dozzle generate'  # no TTY\n// after\nssh -t host 'dozzle generate'","handlingStrategy":"fallback","validationCode":"[ -t 0 ] && echo 'interactive: ensure TTY works' || echo 'piped: provide password on stdin'","typeGuard":null,"tryCatchPattern":"out=$(echo \"$PASSWORD\" | dozzle generate 2>&1) || {\n  echo \"generate failed: $out\" >&2\n  exit 1\n}","preventionTips":["Use non-interactive stdin piping in scripts instead of relying on TTY prompts","Test command execution inside the same environment (ssh, IDE terminal, container) used in production","Use ssh -t when a TTY prompt is required over ssh"],"tags":["cli","terminal","stdin"],"backgroundTag":"file-read-failed","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}