{"record":{"id":"038d854ac2669626","repo":"dgraph-io/dgraph","slug":"while-reading-password","errorCode":null,"errorMessage":"while reading password","messagePattern":"while reading password","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/x.go","lineNumber":1228,"sourceCode":"\tcloseFunc := func() {\n\t\tfor _, c := range conns {\n\t\t\tif err := c.Close(); err != nil {\n\t\t\t\tglog.Warningf(\"Error closing connection to Dgraph client: %v\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn dg, closeFunc\n}\n\n// AskUserPassword prompts the user to enter the password for the given user ID.\nfunc AskUserPassword(userid string, pwdType string, times int) (string, error) {\n\tAssertTrue(times == 1 || times == 2)\n\tAssertTrue(pwdType == \"Current\" || pwdType == \"New\")\n\t// ask for the user's password\n\tfmt.Printf(\"%s password for %v:\", pwdType, userid)\n\tpd, err := term.ReadPassword(int(os.Stdin.Fd()))\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"while reading password\")\n\t}\n\tfmt.Println()\n\tpassword := string(pd)\n\n\tif times == 2 {\n\t\tfmt.Printf(\"Retype %s password for %v:\", strings.ToLower(pwdType), userid)\n\t\tpd2, err := term.ReadPassword(int(os.Stdin.Fd()))\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"while reading password\")\n\t\t}\n\t\tfmt.Println()\n\n\t\tpassword2 := string(pd2)\n\t\tif password2 != password {\n\t\t\treturn \"\", errors.Errorf(\"the two typed passwords do not match\")\n\t\t}\n\t}\n\treturn password, nil","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/x.go#L1210-L1246","documentation":"When prompting for a password on the terminal, term.ReadPassword failed while reading the user's typed input. The underlying OS/terminal error is wrapped with the message 'while reading password', so the root cause is in the wrapped error.","triggerScenarios":"Calling GetPasswordFromUser (login flow) when stdin is not an interactive terminal — e.g. piped input, no TTY, or the terminal closed the read (EOF/interrupt).","commonSituations":"Running commands in CI/non-interactive shells where a password prompt cannot be read, running under sudo/su with redirected stdin, or ssh sessions without a PTY.","solutions":["Run the command in an interactive terminal so the password prompt can be read","Provide credentials non-interactively via the tool's supported flags/env instead of prompting","For CI, allocate a PTY or use a secrets-injection mechanism rather than typing at the prompt"],"exampleFix":"// before\ncat file | myapp login # stdin piped, ReadPassword fails\n// after\nmyapp login # run interactively, or set credentials via env/flags","handlingStrategy":"try-catch","validationCode":"if term.IsTerminal(int(os.Stdin.Fd())) {\n    // safe to prompt\n} else {\n    // use non-interactive credential source\n}","typeGuard":"func stdinIsTTY() bool { return term.IsTerminal(int(os.Stdin.Fd())) }","tryCatchPattern":"pw, err := getPasswordFromUser(...)\nif err != nil {\n    if !term.IsTerminal(int(os.Stdin.Fd())) {\n        return fmt.Errorf(\"password prompt requires a TTY; provide credentials via flags/env: %w\", err)\n    }\n    return err\n}","preventionTips":["Check term.IsTerminal before prompting","Prefer env vars/secret files for CI and non-interactive runs","Allocate a PTY when running remotely (ssh -t)"],"tags":["terminal","password","stdin"],"backgroundTag":"no-tty-for-password-prompt","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}