kovidgoyal/kitty · error
failed to read from file: %#v with error: %w
Error message
failed to read from file: %#v with error: %w
What it means
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.
Source
Thrown at kittens/clipboard/main.go:59
if f := os.NewFile(uintptr(fd), "password-fd"); f == nil {
return 1, fmt.Errorf("invalid file descriptor: %d", fd)
} else {
data, err := io.ReadAll(f)
f.Close()
if err != nil {
return 1, fmt.Errorf("failed to read from file descriptor: %d with error: %w", fd, err)
}
opts.Password = strings.TrimRightFunc(string(data), unicode.IsSpace)
}
} else {
return 1, fmt.Errorf("not a valid file descriptor number: %#v", val)
}
case "file":
if data, err := os.ReadFile(val); err == nil {
opts.Password = strings.TrimRightFunc(string(data), unicode.IsSpace)
} else {
return 1, fmt.Errorf("failed to read from file: %#v with error: %w", val, err)
}
}
}
if len(args) > 0 {
return 0, run_mime_loop(opts, args)
}
if opts.Password != "" || opts.HumanName != "" {
return 1, fmt.Errorf("cannot use --human-name or --password in filter mode")
}
return 0, run_plain_text_loop(opts)
}
func EntryPoint(parent *cli.Command) {
create_cmd(parent, clipboard_main)
}
View on GitHub (pinned to 6d5d0c4406)
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)
Example fix
# before kitten clipboard get --human-name me --password file:/run/secrets/clip-pw # not mounted # after # provision the secret first, then: kitten clipboard get --human-name me --password file:/run/secrets/clip-pw
Defensive patterns
Strategy: validation
Validate before calling
PWFILE=${PW#file:}
[ -f "$PWFILE" ] && [ -r "$PWFILE" ] || { echo "password file missing/unreadable"; exit 2; } Prevention
- Provision secret files before starting the kitten
- Check readability in deployment scripts
- Use absolute paths and mode 600
When it happens
Trigger: `--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.
Common situations: 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.
Related errors
- EPERM
- This kitten should be run as: kitten quick-access-terminal
- Incorrect owner on pwfile: uid={shm.stats.st_uid} gid={shm.s
- Too much piped data
- failed to read the directory %s with error: %w
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/854f17cb25745710.
Report an issue: GitHub.