{"record":{"id":"49080605bda47e68","repo":"gastownhall/beads","slug":"failed-to-walk-directory-tree-w","errorCode":null,"errorMessage":"failed to walk directory tree: %w","messagePattern":"failed to walk directory tree: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/artifacts.go","lineNumber":43,"sourceCode":"\t\tbase := filepath.Base(walkPath)\n\t\tif info.IsDir() && (base == \"node_modules\" || base == \"vendor\" || base == \"__pycache__\") {\n\t\t\treturn filepath.SkipDir\n\t\t}\n\n\t\t// We only care about directories named \".beads\"\n\t\tif !info.IsDir() || base != \".beads\" {\n\t\t\treturn nil\n\t\t}\n\n\t\tr, s, e := cleanBeadsDirArtifacts(walkPath)\n\t\tremoved += r\n\t\tskipped += s\n\t\terrCount += e\n\n\t\treturn filepath.SkipDir\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to walk directory tree: %w\", err)\n\t}\n\n\t// Report summary\n\tfmt.Printf(\"  Artifact cleanup: %d removed, %d skipped, %d errors\\n\", removed, skipped, errCount)\n\n\tif skipped > 0 {\n\t\tfmt.Println(\"  Skipped items may need manual review (e.g., issues.jsonl in dolt dirs, beads.db files)\")\n\t}\n\n\tif errCount > 0 {\n\t\treturn fmt.Errorf(\"%d artifact(s) could not be removed\", errCount)\n\t}\n\n\treturn nil\n}\n\n// cleanBeadsDirArtifacts cleans artifacts from a single .beads directory.\n// Returns counts of removed, skipped, and errored items.","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/artifacts.go#L25-L61","documentation":"ClassicArtifacts cleans up classic-beads artifact files (SQLite WAL/SHM files, backup DBs, JSONL cruft, etc.) by walking the beads directory tree with filepath.Walk. If the Walk callback returns a non-nil, non-SkipDir error, the walk aborts and this error wraps it. The cleanup summary is not printed/complete because the traversal itself failed.","triggerScenarios":"Running the doctor artifacts fix (invoked by the listed tests or the bd doctor fix path) when filepath.Walk fails on the root directory: root path does not exist, permission denied reading a directory, symlink loops, or a custom walk callback error other than the intended SkipDir.","commonSituations":"Beads directory deleted mid-run; directory mounted read-only or with restrictive permissions; running as a user without read access to .beads; root path typo so the walk root is missing (PathError).","solutions":["Read the wrapped %w error: if it's a PathError 'no such file or directory', verify the beads directory path exists before invoking cleanup.","Fix filesystem permissions (chmod/chown) on the beads directory so the process can read and traverse it.","If caused by a walk callback returning an unexpected error, audit the callback so only filepath.SkipDir is returned intentionally and other per-file errors are counted in errCount rather than aborting the walk."],"exampleFix":"// before\nreturn fmt.Errorf(\"read dir: %w\", err) // aborts entire walk\n// after\nerrCount++\nreturn nil // record and continue walking\n// and check root exists before walking:\nif _, err := os.Stat(root); os.IsNotExist(err) { return nil }","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(beadsDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"beads directory %s missing or not a directory\", beadsDir)\n}","typeGuard":null,"tryCatchPattern":"if err := artifacts.ClassicArtifacts(beadsDir); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {\n        // fix permissions or skip cleanup\n    }\n    return err\n}","preventionTips":["Check that the beads directory exists and is readable/writable before running cleanup.","Run bd commands as a user with access to the .beads directory; avoid mixed-ownership files after sudo runs.","In walk callbacks, count per-entry errors instead of returning them, reserving returns for filepath.SkipDir."],"tags":["filesystem","walk","permissions","cleanup"],"backgroundTag":"directory-walk-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}