{"record":{"id":"f5c05a38389e3092","repo":"golang/go","slug":"cannot-embed-irregular-file-s","errorCode":null,"errorMessage":"cannot embed irregular file %s","messagePattern":"cannot embed irregular file (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":2226,"sourceCode":"\t\t\t\t}\n\t\t\t\tif dir != file {\n\t\t\t\t\tif info, err := fsys.Lstat(dir); err == nil && !info.IsDir() {\n\t\t\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed %s %s: in non-directory %s\", what, rel, dir[len(pkgdir)+1:])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdirOK[dir] = true\n\t\t\t\tif elem := filepath.Base(dir); isBadEmbedName(elem) {\n\t\t\t\t\tif dir == file {\n\t\t\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed %s %s: invalid name %s\", what, rel, elem)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed %s %s: in invalid directory %s\", what, rel, elem)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch {\n\t\t\tdefault:\n\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed irregular file %s\", rel)\n\n\t\t\tcase info.Mode().IsRegular():\n\t\t\t\tif have[rel] != pid {\n\t\t\t\t\thave[rel] = pid\n\t\t\t\t\tlist = append(list, rel)\n\t\t\t\t}\n\n\t\t\t// If the embedfollowsymlinks GODEBUG is set to 1, allow the leaf file to be a\n\t\t\t// symlink (#59924). We don't allow directories to be symlinks and have already\n\t\t\t// checked that none of the parent directories of the file are symlinks in the\n\t\t\t// loop above. The file pointed to by the symlink must be a regular file.\n\t\t\tcase embedfollowsymlinks.Value() == \"1\" && info.Mode()&fs.ModeType == fs.ModeSymlink:\n\t\t\t\tinfo, err := fsys.Stat(file)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, err\n\t\t\t\t}\n\t\t\t\tif !info.Mode().IsRegular() {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed irregular file %s\", rel)","sourceCodeStart":2208,"sourceCodeEnd":2244,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L2208-L2244","documentation":"In the switch at line 2225 over the matched file's mode, the default branch fires when info.Mode() is neither regular, nor (with GODEBUG embedfollowsymlinks=1) a symlink, nor a directory. That covers irregular files: device files, named pipes, sockets, etc. go:embed only embeds regular file contents.","triggerScenarios":"An embed glob matches a FIFO, a Unix domain socket, a character/block device, or any non-regular non-directory non-symlink file. The glob can match it because Glob only filters by name, not by type.","commonSituations":"A leftover FIFO/socket created by a dev tool in the package directory; a /dev entry accidentally captured by a wide glob; build artifacts that are pipes used for IPC during tests.","solutions":["Remove the irregular file from the package directory (e.g. `rm` the socket/FIFO).","Narrow the //go:embed glob to specific file extensions so it cannot match the irregular file.","Move the irregular file outside the embedded directory."],"exampleFix":"// before: //go:embed data/*  and data/cli.sock is a socket\n// after: rm data/cli.sock  OR narrow to\n//go:embed data/*.json","handlingStrategy":"validation","validationCode":"// Verify each embed target is a regular file before building.\npackage embedcheck\n\nimport (\n\t\"errors\"\n\t\"os\"\n)\n\nfunc EmbedTargetIsRegular(path string) error {\n\tinfo, err := os.Lstat(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !info.Mode().IsRegular() {\n\t\treturn errors.New(\"refusing to embed non-regular file: \" + path)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep sockets, FIFOs, and device files out of package directories.","Scope embed patterns to specific extensions (`//go:embed data/*.json`) rather than `data/*`."],"tags":["embed","filesystem","go-embed"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}