{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/hugo_sites.go#L321-L357","documentation":"Sent via SendError when HugoSites.Data() triggers the data init resetter (loading /data folders) and it fails. The %w is the underlying data-load error; Data() returns nil and forwards this error to the error channel.","triggerScenarios":"Produced at hugo_sites.go:339 when h.init.data.Do(ctx) returns a non-nil error — i.e. the lazy one-shot loader that walks and parses /data files fails (open/parse/unmarshal of any data file).","commonSituations":"A malformed YAML/JSON/TOML file in /data; a data file that cannot be opened (permissions/encoding); a syntax error introduced by an editor; very large or binary data files causing parse failures.","solutions":["Unwrap the %w — it typically points to 'data: failed to open' or a parse error with file/line context.","Validate every file in /data with the relevant linter (yamllint, jq, toml-cli) and fix syntax errors.","Confirm file encodings are UTF-8 (not UTF-8-BOM / binary) for all /data files.","Temporarily move recently-edited data files aside to isolate the offender."],"exampleFix":"# before: /data/config.yaml with bad indentation\nsite:\n name: Demo\nenabled true   # missing colon\n\n# after\nsite:\n name: Demo\nenabled: true","handlingStrategy":"validation","validationCode":"// Lint all data files before building: yamllint, jq, toml-cli per extension.\nfor _, f := range dataFiles { if err := lintByExt(f); err != nil { return err } }","typeGuard":null,"tryCatchPattern":"if err := h.init.data.Do(ctx); err != nil {\n    // data load failed; surface but allow build to proceed if data is non-critical\n    h.Log.Errorf(\"data load failed (continuing): %v\", err)\n}","preventionTips":["Add a CI step that validates /data syntax on every commit.","Keep data files UTF-8 without BOM.","Avoid binary/temp files inside /data."],"tags":["data","parsing","initialization","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}