{"record":{"id":"e0c56060e38f95b5","repo":"gohugoio/hugo","slug":"template-pattern-matches-no-files-q","errorCode":null,"errorMessage":"template: pattern matches no files: %#q","messagePattern":"template: pattern matches no files: %#q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/htmltemplate/template.go","lineNumber":512,"sourceCode":"}\n\n// ParseFS is like [Template.ParseFiles] or [Template.ParseGlob] but reads from the file system fs\n// instead of the host operating system's file system.\n// It accepts a list of glob patterns.\n// (Note that most file names serve as glob patterns matching only themselves.)\nfunc (t *Template) ParseFS(fs fs.FS, patterns ...string) (*Template, error) {\n\treturn parseFS(t, fs, patterns)\n}\n\nfunc parseFS(t *Template, fsys fs.FS, patterns []string) (*Template, error) {\n\tvar filenames []string\n\tfor _, pattern := range patterns {\n\t\tlist, err := fs.Glob(fsys, pattern)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif len(list) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"template: pattern matches no files: %#q\", pattern)\n\t\t}\n\t\tfilenames = append(filenames, list...)\n\t}\n\treturn parseFiles(t, readFileFS(fsys), filenames...)\n}\n\nfunc readFileOS(file string) (name string, b []byte, err error) {\n\tname = filepath.Base(file)\n\tb, err = os.ReadFile(file)\n\treturn\n}\n\nfunc readFileFS(fsys fs.FS) func(string) (string, []byte, error) {\n\treturn func(file string) (name string, b []byte, err error) {\n\t\tname = path.Base(file)\n\t\tb, err = fs.ReadFile(fsys, file)\n\t\treturn\n\t}","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/htmltemplate/template.go#L494-L530","documentation":"Returned by parseFS (backing ParseFS and t.ParseFS) when fs.Glob on the provided fs.FS for a pattern returns an empty list. Unlike ParseGlob's os-based variant, this operates on an arbitrary io/fs.FS (embed, memory, etc.) and requires each pattern to match at least one file. The %#q quotes the pattern.","triggerScenarios":"Calling template.ParseFS(fsys, patterns...) or t.ParseFS(fsys, patterns...) where one of the patterns matches no entries in fsys (typo, missing file in the embed directive, wrong path prefix in the FS).","commonSituations":"Embed directives that forgot a file or directory; FS path prefix mismatch (e.g. leading slash in embed.FS); renaming a template file but not the pattern; pointing ParseFS at the wrong fs.FS instance.","solutions":["Verify the file exists via fs.ReadDir/fs.Stat on the fsys at the expected path.","Check the embed directive //go:embed includes the needed files/dirs and rebuild.","Correct the pattern (no leading slash for embed.FS; match the exact layout).","Log fsys contents (fs.WalkDir) once during init to catch mismatches early."],"exampleFix":"// before\n//go:embed templats/*\nvar tpls embed.FS\nt, err := template.ParseFS(tpls, \"templats/*.html\") // typo in embed too\n\n// after\n//go:embed templates/*.html\nvar tpls embed.FS\nt, err := template.ParseFS(tpls, \"templates/*.html\")","handlingStrategy":"validation","validationCode":"func parseFSSafe(fsys fs.FS, patterns ...string) (*template.Template, error) {\n    for _, p := range patterns {\n        list, err := fs.Glob(fsys, p)\n        if err != nil { return nil, err }\n        if len(list) == 0 {\n            return nil, fmt.Errorf(\"pattern %q matched nothing in FS\", p)\n        }\n    }\n    return template.ParseFS(fsys, patterns...)\n}","typeGuard":null,"tryCatchPattern":"t, err := template.ParseFS(fsys, patterns...)\nif err != nil && strings.Contains(err.Error(), \"pattern matches no files\") {\n    // dump FS tree to diagnose embed/path issues\n    _ = fs.WalkDir(fsys, \".\", func(p string, d fs.DirEntry, e error) error { return nil })\n}","preventionTips":["Verify embed directives include the template dir and rebuild.","Remember embed.FS paths have no leading slash.","Walk the FS once at startup to confirm expected files exist."],"tags":["go","html-template","parse-fs","embed","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}