{"id":"17458ac6b09b90df","repo":"gohugoio/hugo","slug":"data-failed-to-open-q-w","errorCode":null,"errorMessage":"data: failed to open %q: %w","messagePattern":"data: failed to open %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/hugo_sites.go","lineNumber":729,"sourceCode":"\t\t\t\tif pi == nil {\n\t\t\t\t\tpanic(\"no path info\")\n\t\t\t\t}\n\t\t\t\treturn h.handleDataFile(source.NewFileInfo(fi))\n\t\t\t},\n\t\t})\n\n\tif err := w.Walk(); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc (h *HugoSites) handleDataFile(r *source.File) error {\n\tvar current map[string]any\n\n\tf, err := r.FileInfo().Meta().Open()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"data: failed to open %q: %w\", r.LogicalName(), err)\n\t}\n\tdefer f.Close()\n\n\t// Crawl in data tree to insert data\n\tcurrent = h.data\n\tdataPath := r.FileInfo().Meta().PathInfo.Unnormalized().Dir()[1:]\n\tkeyParts := strings.SplitSeq(dataPath, \"/\")\n\n\tfor key := range keyParts {\n\t\tif key != \"\" {\n\t\t\tif _, ok := current[key]; !ok {\n\t\t\t\tcurrent[key] = make(map[string]any)\n\t\t\t}\n\t\t\tcurrent = current[key].(map[string]any)\n\t\t}\n\t}\n\n\tdata, err := h.readData(r)","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/hugo_sites.go#L711-L747","documentation":"Returned from HugoSites.handleDataFile in hugolib/hugo_sites.go when a file discovered while walking the data/ filesystem cannot be opened for reading. This happens before parsing — it is a filesystem-level failure (permissions, broken symlink, file vanished between walk and open) on the composite data filesystem that overlays project, themes, and module mounts.","triggerScenarios":"The data-directory walk finds a file whose Meta().Open() fails: a symlink in data/ pointing to a nonexistent target, a file without read permission for the build user, a file deleted mid-build (e.g. by a concurrent process while `hugo server` rebuilds), or a module-mounted path that resolved but is unreadable.","commonSituations":"Docker/CI builds where data files are owned by a different UID or volume-mounted with restrictive permissions; symlinked data directories after a repo checkout without symlink support (common on Windows); cloud-synced folders (Dropbox/OneDrive) holding placeholder files; module mounts referencing paths outside the checked-out tree.","solutions":["Identify the file from the quoted name in the error and check it exists and is readable: `ls -l data/<file>` and fix permissions (`chmod +r`).","If it's a symlink, verify the target exists; replace broken symlinks with real files or correct the link.","In Docker/CI, ensure the build user owns or can read the mounted source tree (adjust COPY --chown or volume mount options).","If the file is legitimately gone, remove the stale reference/mount and rebuild."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(filepath.Join(\"data\", name)); err != nil {\n    return fmt.Errorf(\"data file missing/unreadable: %w\", err)\n}","typeGuard":"func isDataOpenErr(err error) bool {\n    var pe *fs.PathError\n    return errors.As(err, &pe) || errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission)\n}","tryCatchPattern":"if err := h.Build(cfg); err != nil {\n    if isDataOpenErr(err) {\n        // filesystem-level failure opening a data file: check permissions, symlinks, mounts\n    }\n    return err\n}","preventionTips":["Check file permissions and broken symlinks under data/ (common in Docker/CI checkouts)","Don't point mounts or module mounts at directories the build user can't read","Fail fast in CI with a clean checkout matching production paths"],"tags":["hugo","data-files","filesystem","permissions"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}