{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/hugo_sites.go#L711-L747","documentation":"Returned by handleDataFile() when opening a data file via its metadata Open() fails. The %q is the data file's logical name; %w is the I/O error. This is the per-file open failure during the data walk.","triggerScenarios":"Raised at hugo_sites.go:729 when r.FileInfo().Meta().Open() returns an error while processing a walked data file — the file was enumerated by the walker but cannot be opened (race, permission, encoding, or it vanished).","commonSituations":"Data file deleted or replaced during the build (watch/CI race); non-UTF-8 or binary file placed in /data that the afero layer rejects; permission/ownership mismatch on /data files after a git checkout on a different OS.","solutions":["Inspect the %q filename and confirm the file exists and is readable at build time.","Fix permissions on the data file and its parent directory.","Exclude non-data files (binaries, temp files) from /data — move them elsewhere.","If triggered by watch, do a clean full rebuild instead of relying on a partial update."],"exampleFix":"# before: binary/backup file committed into /data\nls data/\n# config.yaml  config.yaml~\n\n# after: remove non-data artifacts\nrm data/*~ data/*.bak","handlingStrategy":"validation","validationCode":"// Filter /data to known data extensions before walking.\nvar dataExts = map[string]bool{\"yaml\":true,\"yml\":true,\"json\":true,\"toml\":true}\nif !dataExts[ext(path)] { continue }","typeGuard":null,"tryCatchPattern":"f, err := r.FileInfo().Meta().Open()\nif err != nil {\n    if errors.Is(err, fs.ErrPermission) || errors.Is(err, fs.ErrNotExist) {\n        h.Log.Warnf(\"skip unreadable data file %q: %v\", r.LogicalName(), err); return nil\n    }\n    return fmt.Errorf(\"data: failed to open %q: %w\", r.LogicalName(), err)\n}","preventionTips":["Keep /data free of backups, swaps, and binaries.","Use consistent file permissions in the repo.","Avoid editing /data during a live build."],"tags":["data","io","filesystem","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}