{"id":"b0c44fb34cd40022","repo":"gohugoio/hugo","slug":"failed-to-load-data-w","errorCode":null,"errorMessage":"failed to load data: %w","messagePattern":"failed to load data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/hugo_sites.go","lineNumber":339,"sourceCode":"\tdefer f.mu.Unlock()\n\treturn f.err\n}\n\nfunc (f *fatalErrorHandler) Done() <-chan bool {\n\treturn f.donec\n}\n\ntype hugoSitesInit struct {\n\t// Loads the data from all of the /data folders.\n\tdata hsync.FuncResetter\n\n\t// Loads the Git info and CODEOWNERS for all the pages if enabled.\n\tgitInfo hsync.FuncResetter\n}\n\nfunc (h *HugoSites) Data() map[string]any {\n\tif err := h.init.data.Do(context.Background()); err != nil {\n\t\th.SendError(fmt.Errorf(\"failed to load data: %w\", err))\n\t\treturn nil\n\t}\n\treturn h.data\n}\n\n// Pages returns all pages for all sites.\nfunc (h *HugoSites) Pages() page.Pages {\n\tkey := \"pages\"\n\tv, err := h.cachePages.GetOrCreate(key, func(string) (page.Pages, error) {\n\t\tvar pages page.Pages\n\t\tfor _, s := range h.Sites {\n\t\t\tpages = append(pages, s.Pages()...)\n\t\t}\n\t\tpage.SortByDefault(pages)\n\t\treturn pages, nil\n\t})\n\tif err != nil {\n\t\tpanic(err)","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/hugo_sites.go#L321-L357","documentation":"Returned by HugoSites.Data() in hugolib/hugo_sites.go when the lazy, once-per-build initializer that walks and parses all /data directories fails. Accessing `site.Data` (or .Site.Data in templates) triggers this load; any unreadable or unparseable data file aborts it, and the error is sent to the site's fatal error handler.","triggerScenarios":"First template access to `.Site.Data` (or hugo build touching data) when any file under data/ — in the project, a theme, or a mounted module — fails to open or parse: invalid JSON/YAML/TOML/XML/CSV, unsupported extension handling, or filesystem permission errors.","commonSituations":"Malformed YAML (tabs, unquoted colons) in data/*.yaml; JSON with trailing commas; a data file saved with the wrong extension for its syntax; module mounts pointing data/ at a directory containing non-data files; merge conflicts committed into data files.","solutions":["Read the wrapped error — it names the offending data file and parse position; fix the syntax there.","Validate the file with an external linter (yamllint, jq, taplo) matching its extension.","Ensure every file under data/ has an extension matching its actual format (json/yaml/toml/xml/csv).","Check module/theme mounts in hugo.toml [[module.mounts]] aren't mounting stray files into data/."],"exampleFix":"# data/authors.yaml before (tab indentation — invalid YAML)\nauthors:\n\t- name: Jo\n# after (spaces)\nauthors:\n  - name: Jo","handlingStrategy":"try-catch","validationCode":"# validate data files before build\nfind data -name '*.json' -exec jq empty {} \\;\nfind data -name '*.yaml' -o -name '*.yml' | xargs -I{} yq e '.' {} > /dev/null","typeGuard":null,"tryCatchPattern":"if err := h.Build(cfg); err != nil {\n    if strings.Contains(err.Error(), \"failed to load data\") {\n        // a file under data/ is malformed — the wrapped error names it\n    }\n    return err\n}","preventionTips":["Lint data/ files (jq, yq, TOML checker) in pre-commit","Keep only supported formats (JSON/YAML/TOML/XML/CSV) under data/","Avoid duplicate keys and BOMs in YAML data files"],"tags":["hugo","data-files","yaml","json","configuration"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}