{"record":{"id":"a08bc2484e59ae05","repo":"golang/go","slug":"not-a-regular-file","errorCode":null,"errorMessage":"not a regular file","messagePattern":"not a regular file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/staticdata/data.go","lineNumber":133,"sourceCode":"// fileStringSym returns a symbol for the contents and the size of file.\n// If readonly is true, the symbol shares storage with any literal string\n// or other file with the same content and is placed in a read-only section.\n// If readonly is false, the symbol is a read-write copy separate from any other,\n// for use as the backing store of a []byte.\n// The content hash of file is copied into hashBytes. (If hash is nil, nothing is copied.)\n// The returned symbol contains the data itself, not a string header.\nfunc fileStringSym(pos src.XPos, file string, readonly bool, hashBytes []byte) (*obj.LSym, int64, error) {\n\tf, err := os.Open(file)\n\tif err != nil {\n\t\treturn nil, 0, err\n\t}\n\tdefer f.Close()\n\tinfo, err := f.Stat()\n\tif err != nil {\n\t\treturn nil, 0, err\n\t}\n\tif !info.Mode().IsRegular() {\n\t\treturn nil, 0, fmt.Errorf(\"not a regular file\")\n\t}\n\tsize := info.Size()\n\tif size <= 1*1024 {\n\t\tdata, err := io.ReadAll(f)\n\t\tif err != nil {\n\t\t\treturn nil, 0, err\n\t\t}\n\t\tif int64(len(data)) != size {\n\t\t\treturn nil, 0, fmt.Errorf(\"file changed between reads\")\n\t\t}\n\t\tvar sym *obj.LSym\n\t\tif readonly {\n\t\t\tsym = StringSym(pos, string(data))\n\t\t} else {\n\t\t\tsym = slicedata(pos, string(data))\n\t\t}\n\t\tif len(hashBytes) > 0 {\n\t\t\tsum := hash.Sum32(data)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/staticdata/data.go#L115-L151","documentation":"When processing //go:embed directives, the compiler opens and stats each referenced file via fileStringSym. It checks info.Mode().IsRegular() to ensure the file is a regular file. This error fires when the path resolves to a device, named pipe, socket, or other non-regular file type.","triggerScenarios":"An //go:embed directive that references a named pipe (mkfifo), device file (/dev/null, /dev/urandom), Unix domain socket, or other special file. Broken symlinks that resolve to special files.","commonSituations":"Accidentally embedding system files from /dev, /proc, or /sys. Build environments where FIFO pipes are used for inter-process communication and accidentally matched by embed patterns. Symlinks in the embed directory pointing to devices.","solutions":["Ensure the embed path points to an actual regular file, not a device or pipe","Remove or exclude symlinks that point to special files from the embed directory","Check for accidental embed of system paths: verify each file with 'file' or 'stat' command","If using embed.FS with directory patterns, exclude directories containing special files"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify that embed targets are regular files before building\nimport (\n    \"os\"\n    \"path/filepath\"\n)\n\nfunc validateEmbedTargets(dir string) error {\n    return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {\n        if err != nil {\n            return err\n        }\n        if !info.IsDir() && !info.Mode().IsRegular() {\n            return fmt.Errorf(\"%s is not a regular file (mode: %v)\", path, info.Mode())\n        }\n        return nil\n    })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check embed directories for special files (pipes, sockets, devices) before building","Remove symlinks pointing to non-regular files from embed directories","Avoid embedding from /dev, /proc, /sys, or other virtual filesystems","Use a clean assets directory for embed targets"],"tags":["go-compiler","go-embed","file-system","file-type"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}