{"record":{"id":"dffbaed631e930bd","repo":"wavetermdev/waveterm","slug":"not-a-regular-file-s","errorCode":null,"errorMessage":"not a regular file: %s","messagePattern":"not a regular file: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/fileutil/fileutil.go","lineNumber":345,"sourceCode":"\t\t}\n\n\t\tmodifiedContents, results[i] = applyEdit(modifiedContents, edit, i)\n\t\tif !results[i].Applied {\n\t\t\tfailed = true\n\t\t}\n\t}\n\n\treturn modifiedContents, results\n}\n\nfunc ReplaceInFile(filePath string, edits []EditSpec) error {\n\tfileInfo, err := os.Stat(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to stat file: %w\", err)\n\t}\n\n\tif !fileInfo.Mode().IsRegular() {\n\t\treturn fmt.Errorf(\"not a regular file: %s\", filePath)\n\t}\n\n\tif fileInfo.Size() > MaxEditFileSize {\n\t\treturn fmt.Errorf(\"file too large for editing: %d bytes (max: %d)\", fileInfo.Size(), MaxEditFileSize)\n\t}\n\n\tcontents, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read file: %w\", err)\n\t}\n\n\tmodifiedContents, err := ApplyEdits(contents, edits)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := os.WriteFile(filePath, modifiedContents, fileInfo.Mode()); err != nil {\n\t\treturn fmt.Errorf(\"failed to write file: %w\", err)","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/util/fileutil/fileutil.go#L327-L363","documentation":"Returned when the path exists but is not a regular file (e.g. it is a directory, symlink to a device, socket, or pipe) and a regular file is required for the operation. The path is included via %s.","triggerScenarios":"Calling ReplaceInFile with a directory path, a device node (/dev/...), a named pipe, or a unix socket as filePath.","commonSituations":"Passing a directory where a file was expected (e.g. ~/.config/wave instead of a settings file); resolving a glob or user input to a special file; editing paths under /proc or /sys.","solutions":["Point filePath at an actual file, not a directory or special file.","If a directory was given, resolve to the concrete file inside it (e.g. the settings JSON).","Check with os.Stat and FileInfo.Mode().IsRegular() before calling.","Skip special files in any path-walking code that feeds ReplaceInFile."],"exampleFix":"// before\nfileutil.ReplaceInFile(\"/home/user/.config/wave\", edits) // directory\n\n// after\nfi, _ := os.Stat(path)\nif !fi.Mode().IsRegular() {\n    path = filepath.Join(path, \"settings.json\")\n}\nfileutil.ReplaceInFile(path, edits)","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(path)\nif err == nil && !fi.Mode().IsRegular() {\n    return fmt.Errorf(\"refusing to edit non-regular file: %s\", path)\n}","typeGuard":null,"tryCatchPattern":"// Go: check message or pre-validate mode\nif err := fileutil.ReplaceInFile(path, edits); err != nil {\n    if strings.Contains(err.Error(), \"not a regular file\") {\n        return fmt.Errorf(\"pass a concrete file path, not %s\", path)\n    }\n}","preventionTips":["Never pass directories or /dev, /proc, /sys paths to file-editing APIs","Check FileInfo.Mode().IsRegular() after every Stat","When expanding user input or globs, filter to regular files","Resolve directories to a concrete file (e.g. dir + settings.json)"],"tags":["go","filesystem","validation"],"backgroundTag":"not-a-regular-file","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}