{"record":{"id":"79c65c88955499c9","repo":"larksuite/cli","slug":"not-a-regular-file-directories-devices-fifos-a","errorCode":null,"errorMessage":"not a regular file (directories, devices, FIFOs, and sockets are refused)","messagePattern":"not a regular file \\(directories, devices, FIFOs, and sockets are refused\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/vfs/localfileio/openvalidated_unix.go","lineNumber":67,"sourceCode":"\t\t// map ErrPathValidation to a typed validation error, and the fd checks\n\t\t// are the same verdict the path checks make, one layer later.\n\t\treturn nil, &fileio.PathValidationError{Err: err}\n\t}\n\treturn f, nil\n}\n\n// inspectOpenedFile validates the opened fd and restores blocking mode. pre is\n// nil when there is no prior Stat to compare against.\nfunc inspectOpenedFile(f *os.File, pre os.FileInfo, rejectHardLinks bool) error {\n\tpost, err := f.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot stat opened file: %w\", err)\n\t}\n\tif pre != nil && !os.SameFile(pre, post) {\n\t\treturn fmt.Errorf(\"file changed between validation and open\")\n\t}\n\tif !post.Mode().IsRegular() {\n\t\treturn fmt.Errorf(\"not a regular file (directories, devices, FIFOs, and sockets are refused)\")\n\t}\n\tif rejectHardLinks {\n\t\tif st, ok := post.Sys().(*syscall.Stat_t); ok && st.Nlink > 1 {\n\t\t\treturn fmt.Errorf(\"file has multiple hard links, so the other names it can be reached by \" +\n\t\t\t\t\"cannot be checked (hint: copy the file and use the copy instead)\")\n\t\t}\n\t}\n\tif err := syscall.SetNonblock(int(f.Fd()), false); err != nil {\n\t\treturn fmt.Errorf(\"cannot restore blocking mode: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":49,"sourceCodeEnd":80,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/vfs/localfileio/openvalidated_unix.go#L49-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil { return err }\nif !info.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a regular file (mode %s)\", path, info.Mode())\n}","typeGuard":null,"tryCatchPattern":"var pve *fileio.PathValidationError\nif errors.As(err, &pve) && strings.Contains(pve.Error(), \"not a regular file\") { /* caller passed a dir/device/FIFO/socket */ }","preventionTips":["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"],"tags":["filesystem","file-type","unix"],"backgroundTag":"not-a-regular-file","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}