dgraph-io/dgraph · error

while reading password

Error message

while reading password

What it means

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.

Solutions

  1. Run the command in an interactive terminal so the password prompt can be read
  2. Provide credentials non-interactively via the tool's supported flags/env instead of prompting
  3. For CI, allocate a PTY or use a secrets-injection mechanism rather than typing at the prompt

Example fix

// before
cat file | myapp login # stdin piped, ReadPassword fails
// after
myapp login # run interactively, or set credentials via env/flags
Defensive patterns

Strategy: try-catch

Validate before calling

if term.IsTerminal(int(os.Stdin.Fd())) {
    // safe to prompt
} else {
    // use non-interactive credential source
}

Type guard

func stdinIsTTY() bool { return term.IsTerminal(int(os.Stdin.Fd())) }

Try / catch

pw, err := getPasswordFromUser(...)
if err != nil {
    if !term.IsTerminal(int(os.Stdin.Fd())) {
        return fmt.Errorf("password prompt requires a TTY; provide credentials via flags/env: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/038d854ac2669626. Report an issue: GitHub.

Appendix: source

Thrown at x/x.go:1228

	closeFunc := func() {
		for _, c := range conns {
			if err := c.Close(); err != nil {
				glog.Warningf("Error closing connection to Dgraph client: %v", err)
			}
		}
	}
	return dg, closeFunc
}

// AskUserPassword prompts the user to enter the password for the given user ID.
func AskUserPassword(userid string, pwdType string, times int) (string, error) {
	AssertTrue(times == 1 || times == 2)
	AssertTrue(pwdType == "Current" || pwdType == "New")
	// ask for the user's password
	fmt.Printf("%s password for %v:", pwdType, userid)
	pd, err := term.ReadPassword(int(os.Stdin.Fd()))
	if err != nil {
		return "", errors.Wrapf(err, "while reading password")
	}
	fmt.Println()
	password := string(pd)

	if times == 2 {
		fmt.Printf("Retype %s password for %v:", strings.ToLower(pwdType), userid)
		pd2, err := term.ReadPassword(int(os.Stdin.Fd()))
		if err != nil {
			return "", errors.Wrapf(err, "while reading password")
		}
		fmt.Println()

		password2 := string(pd2)
		if password2 != password {
			return "", errors.Errorf("the two typed passwords do not match")
		}
	}
	return password, nil

View on GitHub (pinned to 759e242be6)