{"record":{"id":"ca7c0e13fca5f1a9","repo":"go-delve/delve","slug":"prompt-for-input-failed","errorCode":null,"errorMessage":"Prompt for input failed.\n","messagePattern":"Prompt for input failed\\.\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/terminal.go","lineNumber":433,"sourceCode":"\t// Ensure that the target process is neither running nor recording by\n\t// making a blocking call.\n\t_, _ = t.client.GetState()\n\n\tfor {\n\t\tlocs = nil\n\n\t\tprompt := defaultPrompt\n\t\tif t.conf != nil && t.conf.Prompt != \"\" {\n\t\t\tprompt = t.expandPrompt(t.conf.Prompt)\n\t\t}\n\n\t\tcmdstr, err := t.promptForInput(prompt)\n\t\tif err != nil {\n\t\t\tif err == io.EOF {\n\t\t\t\tfmt.Fprintln(t.stdout, \"exit\")\n\t\t\t\treturn t.handleExit()\n\t\t\t}\n\t\t\treturn 1, errors.New(\"Prompt for input failed.\\n\")\n\t\t}\n\t\tt.stdout.Echo(prompt + cmdstr + \"\\n\")\n\n\t\tif strings.TrimSpace(cmdstr) == \"\" {\n\t\t\tcmdstr = lastCmd\n\t\t}\n\n\t\tlastCmd = cmdstr\n\n\t\tif err := t.cmds.Call(cmdstr, t); err != nil {\n\t\t\tif _, ok := err.(ExitRequestError); ok {\n\t\t\t\treturn t.handleExit()\n\t\t\t}\n\t\t\t// The type information gets lost in serialization / de-serialization,\n\t\t\t// so we do a string compare on the error message to see if the process\n\t\t\t// has exited, or if the command actually failed.\n\t\t\tif strings.Contains(err.Error(), \"exited\") {\n\t\t\t\tfmt.Fprintln(os.Stderr, err.Error())","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/terminal.go#L415-L451","documentation":"Delve's terminal REPL loop calls promptForInput (a readline-style prompt) to read the next command. If that call fails with anything other than io.EOF, Run returns exit code 1 with 'Prompt for input failed.' This is a terminal I/O failure - stdin is not usable interactively - not a debugger command failure.","triggerScenarios":"Running dlv in an environment with no usable TTY on stdin (stdin closed or redirected from /dev/null, CI pipelines without stdin, non-interactive backgrounds), a missing/failed terminal initialization, or a readline error other than EOF while the prompt loop is active (e.g. in tests like TestBreakpointSave that drive the terminal programmatically).","commonSituations":"CI jobs running `dlv` without a pty; docker exec without -t; scripts piping commands into dlv but keeping the interactive prompt configured; environments where the terminal library cannot allocate a reader (e.g. dumb terminals or closed file descriptors); automated tests that closed stdin before the loop ran.","solutions":["Run dlv with an attached TTY: use `docker run -t`, `script -qec`, or run in a real terminal instead of a pipe","If commands come from a script, use dlv's init file (--init) or batch mode rather than piping into the interactive prompt","Check that stdin is open and readable in your environment (e.g. `dlv < /dev/tty`)","For non-interactive use, prefer `dlv exec ... --continue` or the DAP/RPC headless server instead of the terminal"],"exampleFix":"// before (CI script)\ndlv debug ./app < /dev/null\n\n// after\ndlv debug ./app --init=./cmds.init --continue","handlingStrategy":"try-catch","validationCode":"// Go caller driving terminal programmatically\ncmd, isatty := isTerminal(os.Stdin.Fd())\nif !isatty {\n    // run headless/RPC instead of interactive terminal\n    _ = cmd\n}\n# shell: only start interactive dlv when a TTY exists\n[ -t 0 ] && dlv debug ./app || dlv debug ./app --init=cmds.init --continue","typeGuard":"// Go: check stdin usability before entering interactive mode\nfunc stdinIsTTY() bool {\n    fi, err := os.Stdin.Stat()\n    return err == nil && (fi.Mode()&os.ModeCharDevice) != 0\n}","tryCatchPattern":"// Wrap terminal Run and treat exit-code 1 + this message as a non-TTY environment problem\ncode, err := term.Run()\nif code == 1 && err != nil && strings.Contains(err.Error(), \"Prompt for input failed\") {\n    log.Println(\"stdin is not interactive; use --init, headless mode, or attach a TTY\")\n    os.Exit(code)\n}","preventionTips":["Never close or redirect stdin when driving the terminal programmatically (tests: keep the pipe open until Run returns)","Use -t with docker / script -qec to allocate a pty in CI","Prefer headless `dlv --headless` or the RPC/DAP APIs for non-interactive automation","If piping commands, ensure the stream ends with 'exit\\n' so EOF is handled gracefully"],"tags":["terminal","stdin","tty","repl"],"backgroundTag":"prompt-input-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}