{"record":{"id":"4b70225b7b7898fa","repo":"JuliusBrussee/caveman","slug":"repository-intelligence-cwd-is-not-a-directory","errorCode":null,"errorMessage":"repository intelligence: cwd is not a directory","messagePattern":"repository intelligence: cwd is not a directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/repointel/index.go","lineNumber":154,"sourceCode":"\tChangedPaths   []string `json:\"changed_paths\"`\n\tAffectedTests  []string `json:\"affected_tests\"`\n\tBasis          string   `json:\"basis\"`\n\tEvidenceStatus string   `json:\"evidence_status\"`\n\tConservative   bool     `json:\"conservative\"`\n}\n\nfunc Build(ctx context.Context, root, repositoryState string, queryTerms []string) (Map, Bundle, error) {\n\tresolved, err := filepath.EvalSymlinks(root)\n\tif err != nil {\n\t\treturn Map{}, Bundle{}, err\n\t}\n\tresolved, err = filepath.Abs(resolved)\n\tif err != nil {\n\t\treturn Map{}, Bundle{}, err\n\t}\n\tinfo, err := os.Stat(resolved)\n\tif err != nil || !info.IsDir() {\n\t\treturn Map{}, Bundle{}, errors.New(\"repository intelligence: cwd is not a directory\")\n\t}\n\tfiles, truncated, listingBasis, err := listFiles(ctx, resolved)\n\tif err != nil {\n\t\treturn Map{}, Bundle{}, err\n\t}\n\tpackages := packageBoundaries(files)\n\tactivity := gitActivity(ctx, resolved)\n\tmapped := make([]File, 0, len(files))\n\tfor _, relative := range files {\n\t\tentry := File{\n\t\t\tPath: relative, Language: languageFor(relative), Package: nearestPackage(relative, packages),\n\t\t\tTestFor: testTarget(relative, files), RecentChanges: activity[relative], Convention: isConvention(relative),\n\t\t}\n\t\tif entry.Language != \"\" && !sensitivePath(relative) {\n\t\t\tpath := filepath.Join(resolved, filepath.FromSlash(relative))\n\t\t\tif raw, readErr := os.ReadFile(path); readErr == nil && len(raw) <= maxFileBytes && !containsNUL(raw) {\n\t\t\t\tentry.Imports = scanImports(entry.Language, raw)\n\t\t\t\tentry.Symbols = scanSymbols(ctx, relative, entry.Language, raw)","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/repointel/index.go#L136-L172","documentation":"repointel.Build resolves the given cwd to an absolute path and stats it; if the stat fails or the target is not a directory, it returns this error instead of walking a nonexistent or non-directory root. The repository-intelligence index requires a real directory to enumerate files and package boundaries.","triggerScenarios":"Build(ctx, cwd, ...) called with a path that does not exist, was deleted after being captured, points at a file (not a directory), or is inaccessible due to permissions making os.Stat fail.","commonSituations":"A proxy/config points at a stale cwd after a project was moved or deleted; passing a file path instead of the repo root; running in a container where the mounted workspace path differs; symlink to a removed target.","solutions":["Verify the cwd exists and is a directory before calling Build: stat it and check IsDir().","Fix the configured working directory in the proxy/agent configuration to the actual repository root.","Recreate or remount the missing workspace directory if the project should exist.","Check permissions on the path (and parents) so os.Stat succeeds."],"exampleFix":"// before\nm, _, err := repointel.Build(ctx, cfg.WorkDir)\n// after\nif info, err := os.Stat(cfg.WorkDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"workspace %q missing or not a directory\", cfg.WorkDir)\n}\nm, _, err := repointel.Build(ctx, cfg.WorkDir)","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(cwd)\nif err != nil { return err }\ninfo, err := os.Stat(abs)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"cwd %q must be an existing directory\", cwd)\n}","typeGuard":"func isDirectory(p string) bool {\n    info, err := os.Stat(p)\n    return err == nil && info.IsDir()\n}","tryCatchPattern":"m, b, err := repointel.Build(ctx, cwd)\nif err != nil && strings.Contains(err.Error(), \"cwd is not a directory\") {\n    return fmt.Errorf(\"check the configured working directory: %w\", err)\n}","preventionTips":["Validate the workspace path exists after any config change","Re-resolve cwd at call time instead of caching a path captured earlier","Check mounts/permissions in containerized environments"],"tags":["filesystem","validation","configuration"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}