{"record":{"id":"c95a0d914fb3a2c1","repo":"gohugoio/hugo","slug":"readdata-failed-to-open-data-file-w","errorCode":null,"errorMessage":"readData: failed to open data file: %w","messagePattern":"readData: failed to open data file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/hugo_sites.go","lineNumber":810,"sourceCode":"\t\t\t\t\"higher precedence %T data already in the data tree\", data, r.Path(), higherPrecedentData)\n\t\t}\n\n\tdefault:\n\t\th.Log.Errorf(\"unexpected data type %T in file %s\", data, r.LogicalName())\n\t}\n\n\treturn nil\n}\n\nfunc (h *HugoSites) errWithFileContext(err error, f *source.File) error {\n\trealFilename := f.FileInfo().Meta().Filename\n\treturn herrors.NewFileErrorFromFile(err, realFilename, h.Fs.Source, nil)\n}\n\nfunc (h *HugoSites) readData(f *source.File) (any, error) {\n\tfile, err := f.FileInfo().Meta().Open()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"readData: failed to open data file: %w\", err)\n\t}\n\tdefer file.Close()\n\tcontent := helpers.ReaderToBytes(file)\n\n\tformat := metadecoders.FormatFromString(f.Ext())\n\treturn metadecoders.Default.Unmarshal(content, format)\n}\n","sourceCodeStart":792,"sourceCodeEnd":818,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/hugo_sites.go#L792-L818","documentation":"Returned by HugoSites.readData() when opening the data file to read its bytes fails. Similar to the handleDataFile open error but occurs in the parse path (readData), wrapping with 'readData:' prefix.","triggerScenarios":"Raised at hugo_sites.go:810 when f.FileInfo().Meta().Open() fails inside readData() — the file handle could not be obtained for reading content to unmarshal.","commonSituations":"Same family as 329 but encountered slightly later in the pipeline (after the walker's open succeeded earlier in a race); file removed between walk and read; permission revoked between operations; network/afero-backed data source temporarily unavailable.","solutions":["Reproduce with a clean build (no concurrent editor) to rule out a watch race.","Verify the file named in the error trace is present and readable.","Check for symlinked data files whose target is missing.","If data is on a network/afero mount, ensure stability/retry at the source."],"exampleFix":"// before: broken symlink in data/\nln -s ../shared/langs.yaml data/langs.yaml\n# shared/langs.yaml later removed\n\n// after: remove or fix the symlink\nrm data/langs.yaml\ncp ../shared/langs.yaml data/langs.yaml","handlingStrategy":"try-catch","validationCode":"// Re-stat the file just before opening to detect vanished files.\nif _, err := os.Stat(filename); err != nil { return nil, fmt.Errorf(\"data file gone: %w\", err) }","typeGuard":null,"tryCatchPattern":"file, err := f.FileInfo().Meta().Open()\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) { h.Log.Warnf(\"transient: %v\", err); return nil, nil }\n    return nil, fmt.Errorf(\"readData: failed to open data file: %w\", err)\n}","preventionTips":["Prefer full builds over partial updates when /data changes.","Don't symlink /data to volatile external trees.","Lock the working tree during build in concurrent setups."],"tags":["data","io","parsing","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}