{"record":{"id":"70d7df4cecdac807","repo":"gohugoio/hugo","slug":"html-template-pattern-matches-no-files-q","errorCode":null,"errorMessage":"html/template: pattern matches no files: %#q","messagePattern":"html/template: pattern matches no files: %#q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/htmltemplate/template.go","lineNumber":476,"sourceCode":"// When parsing multiple files with the same name in different directories,\n// the last one mentioned will be the one that results.\n//\n// ParseGlob returns an error if t or any associated template has already been executed.\nfunc (t *Template) ParseGlob(pattern string) (*Template, error) {\n\treturn parseGlob(t, pattern)\n}\n\n// parseGlob is the implementation of the function and method ParseGlob.\nfunc parseGlob(t *Template, pattern string) (*Template, error) {\n\tif err := t.checkCanParse(); err != nil {\n\t\treturn nil, err\n\t}\n\tfilenames, err := filepath.Glob(pattern)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(filenames) == 0 {\n\t\treturn nil, fmt.Errorf(\"html/template: pattern matches no files: %#q\", pattern)\n\t}\n\treturn parseFiles(t, readFileOS, filenames...)\n}\n\n// IsTrue reports whether the value is 'true', in the sense of not the zero of its type,\n// and whether the value has a meaningful truth value. This is the definition of\n// truth used by if and other such actions.\nfunc IsTrue(val any) (truth, ok bool) {\n\treturn template.IsTrue(val)\n}\n\n// ParseFS is like [ParseFiles] or [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 ParseFS(fs fs.FS, patterns ...string) (*Template, error) {\n\treturn parseFS(nil, fs, patterns)\n}","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/htmltemplate/template.go#L458-L494","documentation":"Returned by parseGlob (backing ParseGlob and t.ParseGlob) when filepath.Glob succeeds but matches zero files. ParseGlob requires the pattern to match at least one file. The %#q quotes the offending pattern.","triggerScenarios":"Calling template.ParseGlob(pattern) or t.ParseGlob(pattern) where pattern matches nothing under the current working directory (typo, wrong dir, missing files, wrong glob syntax that matches nothing).","commonSituations":"Running the binary from a different working directory than expected so relative globs miss; deploying without the templates directory; a typo in the glob (e.g. missing extension); CI that runs in a sparse checkout missing layout files.","solutions":["Print/log the absolute pattern and the resolved matches (filepath.Glob) to confirm the path.","Ensure the working directory or use absolute paths / an embed.FS rooted at the binary.","Correct the glob (e.g. add 'layouts/*.html') so it matches at least one file.","Use ParseFS with go:embed so file resolution is independent of cwd."],"exampleFix":"// before\nt, err := template.ParseGlob(\"temlates/*.html\") // typo, no match\n\n// after\nmatches, _ := filepath.Glob(\"templates/*.html\")\nif len(matches) == 0 { return fmt.Errorf(\"no templates under %q\", absDir) }\nt, err := template.ParseGlob(\"templates/*.html\")","handlingStrategy":"validation","validationCode":"func parseGlobSafe(pattern string) (*template.Template, error) {\n    matches, err := filepath.Glob(pattern)\n    if err != nil { return nil, err }\n    if len(matches) == 0 {\n        abs, _ := filepath.Abs(pattern)\n        return nil, fmt.Errorf(\"glob %q (abs %q) matched no files\", pattern, abs)\n    }\n    return template.ParseGlob(pattern)\n}","typeGuard":null,"tryCatchPattern":"t, err := template.ParseGlob(pattern)\nif err != nil && strings.Contains(err.Error(), \"pattern matches no files\") {\n    cwd, _ := os.Getwd()\n    // fix cwd or switch to absolute/embed-based pattern, then retry\n    return template.ParseGlob(filepath.Join(absRoot, pattern))\n}","preventionTips":["Resolve patterns to absolute paths or use embed.FS to avoid cwd issues.","Log filepath.Glob results during init.","In CI, assert the templates directory exists before running."],"tags":["go","html-template","parse-glob","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}