{"record":{"id":"13439c023896b312","repo":"kopia/kopia","slug":"can-t-get-password","errorCode":null,"errorMessage":"can't get password","messagePattern":"can't get password","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/password.go","lineNumber":120,"sourceCode":"\n\tfor range 5 {\n\t\tfmt.Fprint(out, prompt) //nolint:errcheck\n\n\t\tpassBytes, err := term.ReadPassword(fd)\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrap(err, \"password prompt error\")\n\t\t}\n\n\t\tfmt.Fprintln(out) //nolint:errcheck\n\n\t\tif len(passBytes) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\treturn string(passBytes), nil\n\t}\n\n\treturn \"\", errors.New(\"can't get password\")\n}\n\nvar errFdConversionOverflows = errors.New(\"uintptr file descriptor conversion to int overflows\")\n\nfunc intFd(f *os.File) (int, error) {\n\tfd := f.Fd()\n\n\tif fd <= math.MaxInt {\n\t\treturn int(fd), nil\n\t}\n\n\treturn -1, errFdConversionOverflows\n}\n","sourceCodeStart":102,"sourceCodeEnd":134,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/cli/password.go#L102-L134","documentation":"askPass reads the repository password interactively from a terminal (or from stdin when supported). If every read attempt fails or yields nothing (EOF, no TTY, read error), it gives up and returns the generic error \"can't get password\".","triggerScenarios":"Running kopia non-interactively without KOPASSWORD/--password and stdin unavailable or closed; terminal read failing after retries in askPass.","commonSituations":"CI jobs and cron/scripts without a TTY, piped empty stdin, kopia prompts consumed by other tooling, or entering empty input twice.","solutions":["Pass the password explicitly: --password or the KOPASSWORD environment variable","Ensure stdin is an open interactive TTY (avoid `kopia ... < /dev/null`)","Use --use-.saved-credentials or kopia's credentials file for scripted runs","Check terminal emulation/SSH pty allocation when running remotely"],"exampleFix":"// before (script, no TTY)\nkopia repository connect s3 ...\n// after\nKOPASSWORD=secret kopia repository connect s3 ...","handlingStrategy":"fallback","validationCode":"// ensure a TTY or explicit password source before invoking\nif password == \"\" && os.Getenv(\"KOPASSWORD\") == \"\" && !term.IsTerminal(int(os.Stdin.Fd())) {\n    return errors.New(\"no interactive terminal and no KOPASSWORD set\")\n}","typeGuard":null,"tryCatchPattern":"out, err := askPass(...)\nif err != nil {\n    if strings.Contains(err.Error(), \"can't get password\") {\n        // fall back to KOPASSWORD or --password\n    }\n}","preventionTips":["Set KOPASSWORD in scripts/CI","Redirect password via --password or config credentials","Avoid piping empty stdin into kopia prompts"],"tags":["cli","password","terminal","authentication"],"backgroundTag":"missing-credentials","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}