{"record":{"id":"2446ccb013636274","repo":"larksuite/cli","slug":"failed-to-read-input-w","errorCode":null,"errorMessage":"failed to read input: %w","messagePattern":"failed to read input: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/config/init.go","lineNumber":502,"sourceCode":"\t}\n\n\t// Non-terminal: cannot run interactive mode, guide user to --new\n\tif !f.IOStreams.IsTerminal {\n\t\treturn errs.NewValidationError(errs.SubtypeInvalidArgument, \"config init requires a terminal for interactive mode. Run with --new to create a new app:\\n  lark-cli config init --new\\nThis command blocks until setup is complete and outputs a verification URL. Run it in the background, then retrieve the URL from its output.\")\n\t}\n\n\t// Mode 5: Legacy interactive (readline fallback)\n\tfirstApp := (*core.AppConfig)(nil)\n\tif existing != nil {\n\t\tfirstApp = existing.CurrentAppConfig(\"\")\n\t}\n\n\treader := bufio.NewReader(f.IOStreams.In)\n\treadLine := func(prompt string) (string, error) {\n\t\tfmt.Fprintf(f.IOStreams.ErrOut, \"%s: \", prompt)\n\t\tline, err := reader.ReadString('\\n')\n\t\tif err != nil && err != io.EOF {\n\t\t\treturn \"\", fmt.Errorf(\"failed to read input: %w\", err)\n\t\t}\n\t\tif err == io.EOF && strings.TrimSpace(line) == \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"input terminated unexpectedly (EOF)\")\n\t\t}\n\t\treturn strings.TrimSpace(line), nil\n\t}\n\n\tprompt := \"App ID\"\n\tif firstApp != nil && firstApp.AppId != \"\" {\n\t\tprompt += fmt.Sprintf(\" [%s]\", firstApp.AppId)\n\t}\n\tappIdInput, err := readLine(prompt)\n\tif err != nil {\n\t\treturn errs.NewValidationError(errs.SubtypeInvalidArgument, \"%s\", err).WithCause(err)\n\t}\n\n\tprompt = \"App Secret\"\n\tif firstApp != nil && !firstApp.AppSecret.IsZero() {","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/cmd/config/init.go#L484-L520","documentation":"`lark-cli config init` legacy interactive mode reads each answer with bufio.Reader.ReadString('\\n'). If reading fails with a non-EOF error (I/O failure on stdin), the error is wrapped as \"failed to read input\". An EOF with an empty line produces the distinct \"input terminated unexpectedly (EOF)\" error instead.","triggerScenarios":"Running config init when the stdin read fails at the OS level: stdin closed by the shell, a broken pipe from a scripted invocation, device errors, or the input stream being reset mid-prompt.","commonSituations":"Invoking the interactive command inside CI or a non-interactive shell where stdin is /dev/null or a closed fd; a parent process killing the pipe; running under a wrapper that does not allocate a TTY.","solutions":["Run the command in a real interactive terminal so stdin is open and readable.","If scripting, use the non-interactive path: `lark-cli config init --new`, or provide config via flags/env instead of piping answers.","Check for and fix wrappers/CI steps that close or redirect stdin (e.g. `< /dev/null`), or use `script -c` / a pseudo-TTY if interaction is unavoidable."],"exampleFix":"// before: piping answers into an interactive command fails on stdin\n$ echo \"cli_x\\nsecret\" | lark-cli config init\n// after: use the non-interactive creation path\n$ lark-cli config init --new   # blocks until setup completes, prints verification URL","handlingStrategy":"fallback","validationCode":"// Guard before running interactive init\nif !term.IsTerminal(int(os.Stdin.Fd())) {\n\treturn errors.New(\"config init requires a TTY; run with --new for non-interactive setup\")\n}","typeGuard":null,"tryCatchPattern":"if err := runConfigInit(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to read input\") {\n\t\t// fall back to non-interactive creation\n\t\treturn runConfigInitNew()\n\t}\n\treturn err\n}","preventionTips":["Never pipe stdin into interactive commands; use --new or flags.","In CI, check for a TTY before invoking interactive commands.","Avoid wrappers that close stdin; use `script -c` if a pseudo-TTY is required.","Keep terminal sessions attached during the blocking setup flow."],"tags":["io","stdin","cli","interactive"],"backgroundTag":"stdin-read-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}