{"record":{"id":"046aab1775436b02","repo":"GoogleContainerTools/skaffold","slug":"reading-user-input-w","errorCode":null,"errorMessage":"reading user input: %w","messagePattern":"reading user input: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/initializer/prompt/prompt.go","lineNumber":111,"sourceCode":"\treturn chosen, err\n}\n\n// PortForwardResource prompts the user to give a port to forward the current resource on\nfunc portForwardResource(out io.Writer, imageName string) (int, error) {\n\tvar response string\n\tprompt := &survey.Question{\n\t\tPrompt: &survey.Input{Message: fmt.Sprintf(\"Select port to forward for %s (leave blank for none):\", imageName)},\n\t\tValidate: func(val interface{}) error {\n\t\t\tstr := val.(string)\n\t\t\tif _, err := strconv.Atoi(str); err != nil && str != \"\" {\n\t\t\t\treturn errors.New(\"response must be a number, or empty\")\n\t\t\t}\n\t\t\treturn nil\n\t\t},\n\t}\n\terr := ask([]*survey.Question{prompt}, &response)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"reading user input: %w\", err)\n\t}\n\n\tresponse = strings.ToLower(strings.TrimSpace(response))\n\tif response == \"\" {\n\t\treturn 0, nil\n\t}\n\n\tresponseInt, _ := strconv.Atoi(response)\n\treturn responseInt, nil\n}\n\n// ConfirmInitOptions prompts the user to confirm that they are okay with what skaffold will do if they\n// run with the current config\nfunc ConfirmInitOptions(out io.Writer, config *latest.SkaffoldConfig) (bool, error) {\n\tbuilders := strings.Join(util.ListBuilders(&config.Build), \",\")\n\tdeployers := strings.Join(util.ListDeployers(&config.Deploy), \",\")\n\n\tfmt.Fprintf(out, `If you choose to continue, skaffold will do the following:","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/initializer/prompt/prompt.go#L93-L129","documentation":"prompt.PortForwardResource asks the user which resources to port-forward using an interactive survey prompt via the `ask` helper. When `ask` returns an error (the terminal cannot run an interactive survey — e.g. not a TTY, interrupted session, or the survey library fails to read stdin), the error is wrapped with \"reading user input: %w\". It means the initializer could not get the answer it needs to generate skaffold.yaml.","triggerScenarios":"Running `skaffold init` with port-forward prompts when stdin/stdout is not an interactive terminal (CI, piped input), the user aborts the prompt (Ctrl+C), or the survey library fails to initialize.","commonSituations":"Running skaffold init inside Docker/CI where no TTY is attached; running through scripts that redirect stdin; terminal emulators that break survey's ANSI handling.","solutions":["Run skaffold init in an interactive terminal (attach a TTY: `docker run -it ...`).","Use non-interactive flags (e.g. `skaffold init --force` / supply manifest flags) so no prompt is needed.","Pipe valid answers or set --port-forward=false as applicable to skip the prompt."],"exampleFix":"// before\nskaffold init < input.txt\n// after\nskaffold init  # run interactively, or:\nskaffold init --force --port-forward=false","handlingStrategy":"fallback","validationCode":"if !term.IsTerminal(int(os.Stdin.Fd())) {\n    return errors.New(\"skaffold init requires an interactive terminal or non-interactive flags\")\n}","typeGuard":null,"tryCatchPattern":"if err := runInit(); err != nil {\n    if strings.Contains(err.Error(), \"reading user input\") {\n        // fall back to non-interactive init flags\n    }\n}","preventionTips":["Always run init in a TTY-attached session","Prefer non-interactive flags in scripts/CI","Handle Ctrl+C aborts gracefully"],"tags":["interactive-prompt","tty","initializer"],"backgroundTag":"no-tty-interactive-prompt-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}