{"record":{"id":"4886d08af465b1b2","repo":"juicedata/juicefs","slug":"failed-to-read-password-file-s-w","errorCode":null,"errorMessage":"failed to read password file %s: %w","messagePattern":"failed to read password file (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/interface.go","lineNumber":615,"sourceCode":"\t}\n\tdIndex := strings.Index(uri, \"://\") + 3\n\ts := strings.Split(uri[dIndex:atIndex], \":\")\n\n\tif len(s) > 2 {\n\t\treturn \"\", fmt.Errorf(\"invalid uri: %s\", uri)\n\t}\n\n\tif len(s) == 2 && s[1] != \"\" {\n\t\treturn uri, nil\n\t}\n\tpwd := url.UserPassword(\"\", password) // escape only password\n\treturn uri[:dIndex] + s[0] + pwd.String() + uri[atIndex:], nil\n}\n\nfunc readPasswordFromFile(filePath string) (string, error) {\n\tcontent, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read password file %s: %w\", filePath, err)\n\t}\n\treturn strings.TrimSpace(string(content)), nil\n}\n\nfunc setPasswordFromEnv(uri string) (string, error) {\n\tvar password string\n\tvar err error\n\n\tif metaPassword := os.Getenv(\"META_PASSWORD\"); metaPassword != \"\" {\n\t\tpassword = metaPassword\n\t} else if passwordFile := os.Getenv(\"META_PASSWORD_FILE\"); passwordFile != \"\" {\n\t\tpassword, err = readPasswordFromFile(passwordFile)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t} else {\n\t\t// No password source available, return original URI\n\t\treturn uri, nil","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/interface.go#L597-L633","documentation":"readPasswordFromFile could not read the password file specified via --password-file. The original OS error (not found, permissions, etc.) is wrapped with the file path. The error propagates out of metadata URL preparation, so the mount/format command aborts.","triggerScenarios":"Passing `--password-file /path/to/file` where os.ReadFile fails: the file does not exist, the path is wrong, or the process lacks read permission.","commonSituations":"Typo in the password-file path; file deleted or moved after provisioning; running JuiceFS as a different user (e.g. systemd service or container) that lacks permissions; secret mounted at a different path in a container.","solutions":["Verify the file path exists and is readable: `ls -l <path>` and `cat <path>` as the same user running JuiceFS.","Fix permissions (chmod/chown) or run the client as a user with read access.","Update the --password-file argument or the secret mount location (e.g. Kubernetes secret path) to the correct path."],"exampleFix":"// before\n--password-file /etc/juicefs/passwd.txt   # file missing\n// after\n--password-file /etc/juicefs/redis-pass   # verified with ls and cat","handlingStrategy":"validation","validationCode":"test -r \"$PASS_FILE\" || { echo \"cannot read password file $PASS_FILE\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check file existence and readability as the runtime user before launch.","Mount secrets at stable, known paths in containers/systemd units.","Add readiness checks that verify secret files exist at startup."],"tags":["file","password","credentials"],"backgroundTag":"file-read-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}