{"record":{"id":"922037549ae525ef","repo":"gohugoio/hugo","slug":"failed-to-open-file-q-w","errorCode":null,"errorMessage":"failed to open file %q: %w","messagePattern":"failed to open file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/page__meta.go","lineNumber":342,"sourceCode":"\t\t}\n\t\tm.singular = tc.singular\n\n\t\tif m.pageConfigSource.Kind == kinds.KindTerm {\n\t\t\tm.term = paths.TrimLeading(strings.TrimPrefix(m.pathInfo.Unnormalized().Base(), \"/\"+tc.plural))\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// bookmark1\nfunc (h *HugoSites) newPageMetaSourceFromFile(fi hugofs.FileMetaInfo) (*pageMetaSource, error) {\n\tp, err := func() (*pageMetaSource, error) {\n\t\tmeta := fi.Meta()\n\t\topenSource := func() (hugio.ReadSeekCloser, error) {\n\t\t\tr, err := meta.Open()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to open file %q: %w\", meta.Filename, err)\n\t\t\t}\n\t\t\treturn r, nil\n\t\t}\n\n\t\tp := &pageMetaSource{\n\t\t\tf:          source.NewFileInfo(fi),\n\t\t\tpathInfo:   fi.Meta().PathInfo,\n\t\t\topenSource: openSource,\n\t\t}\n\n\t\treturn p, nil\n\t}()\n\tif err != nil {\n\t\treturn nil, hugofs.AddFileInfoToError(err, fi, h.SourceFs)\n\t}\n\n\treturn p, err\n}","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/page__meta.go#L324-L360","documentation":"From HugoSites.newPageMetaSourceFromFile's openSource closure (page__meta.go:342). It calls meta.Open() to obtain a reader for a content source file; if the OS/hugo filesystem returns an error (file vanished, permission denied, I/O error) it is wrapped with the filename so the offending file is identifiable.","triggerScenarios":"A content file that was present during enumeration is gone or unreadable when Hugo opens it — typical on watch rebuilds where an editor does an atomic save/replace, or when permissions/ownership block the read. The underlying %w is the fs error (ENOENT, EACCES).","commonSituations":"Editor atomic-save race during `hugo server`; file moved/deleted between discovery and open; container/CI filesystem permission mismatch; antivirus/locking on Windows.","solutions":["Confirm the file exists and is readable at the reported path.","On watch, trigger another rebuild after the editor has finished saving.","Fix permissions/ownership of the content tree.","Disable any process locking the content files (antivirus, sync clients)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// library/watch use: tolerate transient open failures and re-run the build\n// if isTransientOpenErr(err) { rebuildOnce() }","typeGuard":null,"tryCatchPattern":"if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission) {\n    // file vanished mid-save or unreadable: retry / fix perms\n}","preventionTips":["On watch, debounce editor saves so files aren't read mid-replace.","Ensure the content tree is readable by the Hugo process.","Disable file lockers (antivirus/sync) over the content directory."],"tags":["file-io","watch","permissions","page"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}