{"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":104,"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, 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":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/proxy/internal/repointel/index.go#L86-L122","documentation":"repointel.Build resolves the root path through symlink evaluation and absolutization, then stats it. If stat fails or the result is not a directory, it reports that the cwd/repository root is not a directory. Note the error also masks the underlying stat error, so permission problems surface the same way.","triggerScenarios":"Calling Build with a path that is a file (e.g. go.mod, a symlink to a file), a deleted directory, or a directory the process cannot stat due to permissions.","commonSituations":"Passing the repo's manifest file instead of its root; root resolved from config pointing at a mounted/unmounted volume; symlink chains that EvalSymlinks resolves to a file; sandboxed environments denying stat.","solutions":["Pass the repository root directory, not any file inside it","Verify the path exists and is a directory before calling Build (os.Stat + IsDir)","If permissions are suspect, check the resolved path's modes and the mount state"],"exampleFix":"// before\nmap, bundle, err := repointel.Build(ctx, \"repo/go.mod\", state, terms)\n\n// after\ninfo, err := os.Stat(root)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"root %q is not a directory\", root)\n}\nmap, bundle, err := repointel.Build(ctx, root, state, terms)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(root)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"root %q is not a directory\", root)\n}\nmp, bundle, err := repointel.Build(ctx, root, state, terms)","typeGuard":"func isDir(p string) bool {\n    info, err := os.Stat(p)\n    return err == nil && info.IsDir()\n}","tryCatchPattern":null,"preventionTips":["Pass repository roots, never files, to Build","Resolve symlinks yourself first to see what the path really points at"],"tags":["repointel","go","validation","filesystem","path"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}