{"record":{"id":"e3d043db15716e6c","repo":"golang/go","slug":"cannot-embed-directory-s-contains-no-embeddable","errorCode":null,"errorMessage":"cannot embed directory %s: contains no embeddable files","messagePattern":"cannot embed directory (.+?): contains no embeddable files","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":2299,"sourceCode":"\t\t\t\t\t\t\treturn filepath.SkipDir\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\t\t\t\t\tif !d.Type().IsRegular() {\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\t\t\t\t\tcount++\n\t\t\t\t\tif have[rel] != pid {\n\t\t\t\t\t\thave[rel] = pid\n\t\t\t\t\t\tlist = append(list, rel)\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t})\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 count == 0 {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed directory %s: contains no embeddable files\", rel)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif len(list) == 0 {\n\t\t\treturn nil, nil, fmt.Errorf(\"no matching files found\")\n\t\t}\n\t\tsort.Strings(list)\n\t\tpmap[pattern] = list\n\t}\n\n\tfor file := range have {\n\t\tfiles = append(files, file)\n\t}\n\tsort.Strings(files)\n\treturn files, pmap, nil\n}\n","sourceCodeStart":2281,"sourceCodeEnd":2317,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L2281-L2317","documentation":"After WalkDir completes over an embedded directory (line 2298), if count == 0 the loader rejects it: the directory exists but contains zero embeddable files. Embeddable files are visible (no leading '.'/'_'), have a valid name, are regular, and are inside the same module. An all-excluded directory is treated as an error, not silently empty, so typos in the path do not produce silent empty embeds.","triggerScenarios":"//go:embed of a directory whose only entries are hidden ('.'/'_' prefix), badly named, irregular, in a nested module, or non-regular. The directory WalkDir'd is structurally present but yields count 0.","commonSituations":"Embedding a templates folder that only contains `.gitkeep` or `_partials`; an assets dir where everything was moved into a hidden cache; an empty build output directory.","solutions":["Add at least one regular, non-hidden, validly-named file to the directory.","Rename files you want embedded so they do not start with '.' or '_'.","If the directory is legitimately empty, remove the //go:embed directive for it."],"exampleFix":"// before: //go:empty_dir  containing only .gitkeep\n// after: add empty_dir/placeholder.txt, or drop the directive","handlingStrategy":"validation","validationCode":"// Confirm an embedded directory has at least one embeddable (visible,\n// validly-named, regular) file before building.\npackage embedcheck\n\nimport (\n\t\"errors\"\n\t\"os\"\n)\n\nfunc EmbedDirHasFiles(dir string) error {\n\tcount := 0\n\terr := filepath.WalkDir(dir, func(p string, d os.DirEntry, err error) error {\n\t\tif err != nil || d.IsDir() {\n\t\t\treturn nil\n\t\t}\n\t\tname := d.Name()\n\t\tif name[0] == '.' || name[0] == '_' {\n\t\t\treturn nil\n\t\t}\n\t\tif !d.Type().IsRegular() {\n\t\t\treturn nil\n\t\t}\n\t\tif err := ValidEmbedFileName(name); err != nil {\n\t\t\treturn nil // badly-named files are skipped, not counted\n\t\t}\n\t\tcount++\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tif count == 0 {\n\t\treturn errors.New(\"embedded directory \" + dir + \" has no embeddable files\")\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not point //go:embed at output directories that may be empty in CI.","If a directory is intentionally empty, remove its //go:embed directive."],"tags":["embed","filesystem","go-embed"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}