{"record":{"id":"7fd6e14a8a366ccb","repo":"alibaba/open-code-review","slug":"file-path-q-must-be-relative-not-absolute","errorCode":null,"errorMessage":"file path %q must be relative, not absolute","messagePattern":"file path %q must be relative, not absolute","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/diff/workspace_file.go","lineNumber":20,"sourceCode":"// Copyright 2026 alibaba/open-code-review Contributors\n\npackage diff\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\n\t\"github.com/alibaba/open-code-review/internal/pathutil\"\n)\n\nfunc readWorkspaceFileForDiff(repoDir, relPath string) ([]byte, error) {\n\trepoRoot, err := pathutil.CanonicalPath(repoDir)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"resolve repository path %q: %w\", repoDir, err)\n\t}\n\tif filepath.IsAbs(relPath) {\n\t\treturn nil, fmt.Errorf(\"file path %q must be relative, not absolute\", relPath)\n\t}\n\n\tfullPath := filepath.Join(repoRoot, relPath)\n\tif !pathutil.WithinBase(repoRoot, fullPath) {\n\t\treturn nil, fmt.Errorf(\"file path %q is outside repository\", relPath)\n\t}\n\n\tparent, err := filepath.EvalSymlinks(filepath.Dir(fullPath))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"resolve parent path for %q: %w\", relPath, err)\n\t}\n\tif !pathutil.WithinBase(repoRoot, parent) {\n\t\treturn nil, fmt.Errorf(\"file path %q is outside repository\", relPath)\n\t}\n\n\tinfo, err := os.Lstat(fullPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"stat file %q: %w\", relPath, err)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/diff/workspace_file.go#L2-L38","documentation":"readWorkspaceFileForDiff rejects the relative path passed for an untracked/workspace file because it is absolute. The diff pipeline always supplies repo-relative paths; an absolute path here would bypass the repo-confinement checks that follow, so it is treated as invalid input.","triggerScenarios":"Thrown at internal/diff/workspace_file.go:20 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the path relative to the repository root (e.g. src/foo.go, not /home/user/repo/src/foo.go)","Strip any repository-root prefix before calling the workspace diff reader","Workspace files are resolved as filepath.Join(repoRoot, relPath); supply relPath accordingly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}