{"id":"f417297cb828b2ac","repo":"gohugoio/hugo","slug":"walk-readdir-w","errorCode":null,"errorMessage":"walk: Readdir: %w","messagePattern":"walk: Readdir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugofs/walk.go","lineNumber":172,"sourceCode":"\t}\n\n\tif dirEntries == nil {\n\t\tf, err := w.cfg.Fs.Open(path)\n\t\tif err != nil {\n\t\t\tif w.checkErr(path, err) {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"walk: open: path: %q filename: %q: %s\", path, info.Meta().Filename, err)\n\t\t}\n\t\tfis, newCtx, err := ReadDirWithContext(ctx, f, -1)\n\t\tctx = newCtx\n\n\t\tf.Close()\n\t\tif err != nil {\n\t\t\tif w.checkErr(path, err) {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"walk: Readdir: %w\", err)\n\t\t}\n\n\t\tdirEntries = DirEntriesToFileMetaInfos(fis)\n\t\tfor _, fi := range dirEntries {\n\t\t\tif fi.Meta().PathInfo == nil {\n\t\t\t\tfi.Meta().PathInfo = w.cfg.PathParser.Parse(\"\", filepath.Join(pathRel, fi.Name()))\n\t\t\t}\n\t\t}\n\n\t\tif w.cfg.SortDirEntries {\n\t\t\tsort.Slice(dirEntries, func(i, j int) bool {\n\t\t\t\treturn dirEntries[i].Name() < dirEntries[j].Name()\n\t\t\t})\n\t\t}\n\n\t}\n\n\tif w.cfg.IgnoreFile != nil {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugofs/walk.go#L154-L190","documentation":"Once a directory is open, Walkway.walk calls ReadDirWithContext to list its entries. A failure reading the directory listing (other than a tolerated not-exist) is wrapped with %w as \"walk: Readdir: ...\" and aborts the walk. Because it uses %w, the underlying OS error remains inspectable by callers via errors.Is/As.","triggerScenarios":"Readdir on an already-opened directory failing: I/O errors on the underlying storage, the directory being removed mid-listing, network filesystem hiccups (NFS/SMB), or errors surfaced by Hugo's composite/overlay filesystems while merging mount entries.","commonSituations":"Building from network shares or cloud-synced folders (Dropbox/OneDrive placeholders that fail on enumeration), flaky container volumes, or directories deleted by another process during `hugo server` watch rebuilds.","solutions":["Inspect the wrapped OS error for the root cause (I/O error, stale handle) and check the health of the underlying storage.","Move the project off cloud-sync placeholder folders or force files to be locally available before building.","If it happens during watch rebuilds when directories are deleted, re-run the build; exclude tooling temp directories from content mounts."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := w.Walk()\nif err != nil {\n\t// %w-wrapped: unwrap with errors.As(&pathErr) to get the failing directory\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) { /* pe.Path names the unreadable dir */ }\n}","preventionTips":["Same hygiene as open: readable directories, no mid-walk mutation, stable filesystem.","Watch for directories that disappear between open and Readdir (temp dirs, editor swap dirs) — exclude them from mounts.","This error wraps with %w, so use errors.Is/errors.As rather than string matching to classify it."],"tags":["hugo","filesystem","walk","readdir","io"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}