{"record":{"id":"cd8712da81aa7e50","repo":"apache/answer","slug":"read-email-input-failed-w","errorCode":null,"errorMessage":"read email input failed: %w","messagePattern":"read email input failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":108,"sourceCode":"\n\tdataData, dataCleanup, err := data.NewData(db, cache)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initialize data layer failed: %w\", err)\n\t}\n\tdefer dataCleanup()\n\n\tuserRepo := user.NewUserRepo(dataData)\n\tauthRepo := auth.NewAuthRepo(dataData)\n\tapiKeyRepo := api_key.NewAPIKeyRepo(dataData)\n\tauthSvc := authService.NewAuthService(authRepo, apiKeyRepo)\n\n\temail := strings.TrimSpace(opts.Email)\n\tif email == \"\" {\n\t\treader := bufio.NewReader(os.Stdin)\n\t\tfmt.Print(\"Please input user email: \")\n\t\temailInput, err := reader.ReadString('\\n')\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"read email input failed: %w\", err)\n\t\t}\n\t\temail = strings.TrimSpace(emailInput)\n\t}\n\n\tuserInfo, exist, err := userRepo.GetByEmail(ctx, email)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"query user failed: %w\", err)\n\t}\n\tif !exist {\n\t\treturn fmt.Errorf(\"user not found: %s\", email)\n\t}\n\n\tfmt.Printf(\"You are going to reset password for user: %s\\n\", email)\n\n\tpassword := strings.TrimSpace(opts.Password)\n\n\tif password != \"\" {\n\t\tprintWarning(\"Passing password via command line may be recorded in shell history\")","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L90-L126","documentation":"ResetPassword wraps a failure from reading the user's email from stdin via bufio.Reader.ReadString('\\n') when opts.Email was empty. This happens in interactive prompts; typically it means stdin was closed or an I/O error occurred.","triggerScenarios":"ResetPassword invoked without --email (or with empty opts.Email) in a non-interactive context — piped input exhausted, stdin closed, no TTY.","commonSituations":"Running the CLI in CI/scripts without passing the email flag, docker run without -i, output piped so stdin is /dev/null.","solutions":["Pass the email explicitly via options (opts.Email) instead of relying on stdin.","Run interactively with a real TTY (e.g. docker run -it).","If piping input, ensure the email line is present on stdin."],"exampleFix":"// before\n_ = cli.ResetPassword(ctx, dataDir, &cli.ResetPasswordOptions{})\n// after\n_ = cli.ResetPassword(ctx, dataDir, &cli.ResetPasswordOptions{Email: \"admin@example.com\"})","handlingStrategy":"validation","validationCode":"if opts.Email == \"\" && term.IsTerminal(int(os.Stdin.Fd())) == false {\n    return fmt.Errorf(\"non-interactive session: pass --email\")\n}","typeGuard":null,"tryCatchPattern":"if err := cli.ResetPassword(ctx, dataDir, &ResetPasswordOptions{}); err != nil {\n    if strings.Contains(err.Error(), \"read email input failed\") {\n        log.Fatalf(\"stdin unavailable; pass --email explicitly: %v\", err)\n    }\n}","preventionTips":["Always pass --email in scripts/CI","Use docker run -it for interactive commands","Never rely on stdin when output is piped"],"tags":["stdin","cli","interactive"],"backgroundTag":"stdin-read-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}