{"record":{"id":"854f17cb25745710","repo":"kovidgoyal/kitty","slug":"failed-to-read-from-file-v-with-error-w","errorCode":null,"errorMessage":"failed to read from file: %#v with error: %w","messagePattern":"failed to read from file: %#v with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/clipboard/main.go","lineNumber":59,"sourceCode":"\t\t\t\tif f := os.NewFile(uintptr(fd), \"password-fd\"); f == nil {\n\t\t\t\t\treturn 1, fmt.Errorf(\"invalid file descriptor: %d\", fd)\n\t\t\t\t} else {\n\t\t\t\t\tdata, err := io.ReadAll(f)\n\t\t\t\t\tf.Close()\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn 1, fmt.Errorf(\"failed to read from file descriptor: %d with error: %w\", fd, err)\n\t\t\t\t\t}\n\t\t\t\t\topts.Password = strings.TrimRightFunc(string(data), unicode.IsSpace)\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\treturn 1, fmt.Errorf(\"not a valid file descriptor number: %#v\", val)\n\t\t\t}\n\t\tcase \"file\":\n\t\t\tif data, err := os.ReadFile(val); err == nil {\n\t\t\t\topts.Password = strings.TrimRightFunc(string(data), unicode.IsSpace)\n\t\t\t} else {\n\t\t\t\treturn 1, fmt.Errorf(\"failed to read from file: %#v with error: %w\", val, err)\n\t\t\t}\n\t\t}\n\t}\n\tif len(args) > 0 {\n\t\treturn 0, run_mime_loop(opts, args)\n\t}\n\tif opts.Password != \"\" || opts.HumanName != \"\" {\n\t\treturn 1, fmt.Errorf(\"cannot use --human-name or --password in filter mode\")\n\t}\n\treturn 0, run_plain_text_loop(opts)\n}\n\nfunc EntryPoint(parent *cli.Command) {\n\tcreate_cmd(parent, clipboard_main)\n}\n","sourceCodeStart":41,"sourceCodeEnd":75,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/clipboard/main.go#L41-L75","documentation":"For --password file:PATH, the kitten reads the file with os.ReadFile; any failure (missing file, permissions, directory) is wrapped together with the path and the underlying OS error.","triggerScenarios":"`--password file:/nonexistent/path`, an unreadable file (mode 600 owned by another user), or a path that is a directory; SELinux/AppArmor denials also land here.","commonSituations":"Deployments where the password file is provisioned by a secret manager that failed to mount; wrong path relative to the kitten's working directory; restrictive permissions in containers or hardened systems.","solutions":["Confirm the file exists and is readable by the kitten process: `test -r /path/pw && echo ok`","Fix permissions: `chmod 600 /path/pw` and correct ownership","Use an absolute path; if the file is generated at runtime, ensure it is written before the kitten starts","Check the wrapped %w error for the real cause (ENOENT vs EACCES)"],"exampleFix":"# before\nkitten clipboard get --human-name me --password file:/run/secrets/clip-pw  # not mounted\n# after\n# provision the secret first, then:\nkitten clipboard get --human-name me --password file:/run/secrets/clip-pw","handlingStrategy":"validation","validationCode":"PWFILE=${PW#file:}\n[ -f \"$PWFILE\" ] && [ -r \"$PWFILE\" ] || { echo \"password file missing/unreadable\"; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provision secret files before starting the kitten","Check readability in deployment scripts","Use absolute paths and mode 600"],"tags":["kitty","clipboard","file-io","permissions"],"backgroundTag":"file-read-permission-denied","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}