{"record":{"id":"03373a3cca8bd293","repo":"alibaba/open-code-review","slug":"resolve-path-w","errorCode":null,"errorMessage":"resolve path: %w","messagePattern":"resolve path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/review_cmd.go","lineNumber":450,"sourceCode":"\t\treturn session.ReviewModeRange\n\t}\n\treturn session.ReviewModeWorkspace\n}\n\n// resolveRepoDir resolves the repo dir for `ocr rules check`. It delegates to\n// resolveWorkingDir(requireGit=true) so it anchors at the git top-level just\n// like the review path — keeping rule resolution consistent when run from a\n// monorepo subdirectory (#287).\nfunc resolveRepoDir(input string) (string, error) {\n\tabsPath, _, err := resolveWorkingDir(input, true)\n\treturn absPath, err\n}\n\n// requireGitRepo validates that the given directory is part of a git repository.\nfunc requireGitRepo(dir string) error {\n\trepoDir, err := filepath.Abs(dir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"resolve path: %w\", err)\n\t}\n\tout, err := runGitCmd(repoDir, \"rev-parse\", \"--git-dir\")\n\tif err != nil || len(out) == 0 {\n\t\treturn fmt.Errorf(\"%s is not a git repository, code review requires a valid git repository\", repoDir)\n\t}\n\treturn nil\n}\n\n// validateReviewRefs rejects ref-option injection (#112): any --from/--to/\n// --commit value must be a real commit ref and must not start with '-'.\nfunc validateReviewRefs(repoDir string, opts reviewOptions) error {\n\trefs := []struct {\n\t\tflag string\n\t\tref  string\n\t}{\n\t\t{\"--from\", opts.from},\n\t\t{\"--to\", opts.to},\n\t\t{\"--commit\", opts.commit},","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/review_cmd.go#L432-L468","documentation":"requireGitRepo converts the supplied directory to an absolute path before probing it with `git rev-parse --git-dir`. If filepath.Abs fails, the error is wrapped as \"resolve path\". filepath.Abs only fails when the working directory or the path cannot be resolved (e.g. deleted cwd), so this is rare.","triggerScenarios":"Calling requireGitRepo (directly or via tests TestRequireGitRepo_Valid/Invalid) with a path that cannot be made absolute — typically because the current working directory no longer exists.","commonSituations":"Running the CLI from a directory that was deleted or renamed while the process held it as cwd; symlink/permission problems on an ancestor directory.","solutions":["Re-run the command from an existing directory (`cd` to a valid path first).","Verify the directory passed to requireGitRepo exists and its ancestors are accessible (ls the parent chain).","Check for permission issues on ancestor directories (`namei -l /path/to/dir`)."],"exampleFix":"// before (cwd deleted)\nocr rules check --repo . file.go\n// after\ncd /valid/path && ocr rules check --repo . file.go","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(dir)\nif err != nil {\n    return fmt.Errorf(\"resolve path: %w\", err)\n}\nif _, err := os.Stat(abs); err != nil {\n    return fmt.Errorf(\"directory %s unavailable: %w\", abs, err)\n}","typeGuard":null,"tryCatchPattern":"if err := requireGitRepo(dir); err != nil {\n    if strings.Contains(err.Error(), \"resolve path\") {\n        // cwd or path invalid; chdir to a valid directory first\n    }\n    return err\n}","preventionTips":["Never delete/rename the directory the process is running from.","Use absolute --repo paths in scripts and CI.","Check ancestor-directory permissions when paths behave oddly."],"tags":["filesystem","path"],"backgroundTag":"path-resolution-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}