larksuite/cli · error
not a regular file (directories, devices, FIFOs, and sockets
Error message
not a regular file (directories, devices, FIFOs, and sockets are refused)
What it means
The opened path resolved to something other than a regular file. The library only allows regular files because directories, devices, FIFOs, and sockets have non-file semantics (reads can block, return EOF, or leak device behavior) and are not what the path policy approved.
Source
Thrown at internal/vfs/localfileio/openvalidated_unix.go:67
// map ErrPathValidation to a typed validation error, and the fd checks
// are the same verdict the path checks make, one layer later.
return nil, &fileio.PathValidationError{Err: err}
}
return f, nil
}
// inspectOpenedFile validates the opened fd and restores blocking mode. pre is
// nil when there is no prior Stat to compare against.
func inspectOpenedFile(f *os.File, pre os.FileInfo, rejectHardLinks bool) error {
post, err := f.Stat()
if err != nil {
return fmt.Errorf("cannot stat opened file: %w", err)
}
if pre != nil && !os.SameFile(pre, post) {
return fmt.Errorf("file changed between validation and open")
}
if !post.Mode().IsRegular() {
return fmt.Errorf("not a regular file (directories, devices, FIFOs, and sockets are refused)")
}
if rejectHardLinks {
if st, ok := post.Sys().(*syscall.Stat_t); ok && st.Nlink > 1 {
return fmt.Errorf("file has multiple hard links, so the other names it can be reached by " +
"cannot be checked (hint: copy the file and use the copy instead)")
}
}
if err := syscall.SetNonblock(int(f.Fd()), false); err != nil {
return fmt.Errorf("cannot restore blocking mode: %w", err)
}
return nil
}
View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Pass a path to an actual regular file, not a directory or device
- If you meant a directory, use the directory-oriented command instead
- Remove or avoid FIFO/socket placeholders at that path (check with ls -l)
- If reading pseudo-files like /proc/*, copy the content to a regular file first
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(path)
if err != nil { return err }
if !info.Mode().IsRegular() {
return fmt.Errorf("%s is not a regular file (mode %s)", path, info.Mode())
} Try / catch
var pve *fileio.PathValidationError
if errors.As(err, &pve) && strings.Contains(pve.Error(), "not a regular file") { /* caller passed a dir/device/FIFO/socket */ } Prevention
- os.Stat and check Mode().IsRegular() before handing the path to the CLI
- Never point file commands at directories, /dev/*, pipes, or sockets
- Clean up stale FIFO/socket placeholder files in target directories
When it happens
Trigger: Calling a vfs read/open-file operation with a path that is a directory, a character/block device (/dev/*), a FIFO (mkfifo), or a Unix socket. O_NONBLOCK prevents a writer-less FIFO from hanging the open, then the regular-file check refuses it.
Common situations: Pointing the CLI at a directory by mistake; passing a device node or /proc,/sys pseudo-file; a FIFO created by a build/test harness; stale socket paths from daemons.
Related errors
- %w (lock: %s, syscall: %v)
- cannot stat opened file: %w
- file changed between validation and open
- file has multiple hard links, so the other names it can be r
- cannot restore blocking mode: %w
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/79c65c88955499c9.
Report an issue: GitHub.