{"record":{"id":"28a80318dc6a69f5","repo":"golang/go","slug":"cannot-embed-s-s-in-invalid-directory-s","errorCode":null,"errorMessage":"cannot embed %s %s: in invalid directory %s","messagePattern":"cannot embed (.+?) (.+?): in invalid directory (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":2219,"sourceCode":"\t\t\t}\n\n\t\t\t// Check that directories along path do not begin a new module\n\t\t\t// (do not contain a go.mod).\n\t\t\tfor dir := file; len(dir) > len(pkgdir)+1 && !dirOK[dir]; dir = filepath.Dir(dir) {\n\t\t\t\tif _, err := fsys.Stat(filepath.Join(dir, \"go.mod\")); err == nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"cannot embed %s %s: in different module\", what, rel)\n\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.","sourceCodeStart":2201,"sourceCodeEnd":2237,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L2201-L2237","documentation":"Companion to 884, same isBadEmbedName check at line 2218, but here dir != file — i.e. an ANCESTOR directory (not the leaf file) has a base name that is invalid for embedding. The offending directory name is reported.","triggerScenarios":"Embedding `sub dir/file.txt` where the directory `sub dir` contains a space; an embedded tree that contains a folder with parentheses or non-ASCII characters in its name.","commonSituations":"Folder names created by designers/PMs with spaces or special characters; localized folder names; vendored assets dropped into a folder with a bad name.","solutions":["Rename the offending ancestor directory so every component uses only ASCII letters, digits, dot, underscore, hyphen.","Reorganize the embedded tree to drop the problematic folder level.","If you cannot rename, copy the assets into a cleanly-named directory as a build step."],"exampleFix":"// before: //go:embed assets v2/data.json  (folder has a space)\n// after: rename to assets_v2/, then\n//go:embed assets_v2/data.json","handlingStrategy":"validation","validationCode":"// Same character rule as 884, but applied to every DIRECTORY component\n// of the embed path, not just the leaf.\npackage embedcheck\n\nimport (\n\t\"errors\"\n\t\"strings\"\n\t\"unicode/utf8\"\n)\n\nfunc ValidEmbedDirNames(rel string) error {\n\tfor _, seg := range strings.Split(filepath.ToSlash(rel), \"/\") {\n\t\tif seg == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tfor _, r := range seg {\n\t\t\tif r >= utf8.RuneSelf {\n\t\t\t\treturn errors.New(\"non-ASCII char in embed dir: \" + seg)\n\t\t\t}\n\t\t\tswitch {\n\t\t\tcase 'a' <= r && r <= 'z', 'A' <= r && r <= 'Z', '0' <= r && r <= '9':\n\t\t\tcase r == '.', r == '_', r == '-':\n\t\t\tdefault:\n\t\t\t\treturn errors.New(\"disallowed char in embed dir: \" + seg)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep embedded directory names ASCII and free of spaces/punctuation.","When accepting assets from designers, rename folders during the import step."],"tags":["embed","filesystem","naming","go-embed"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}