{"record":{"id":"1883431e8d415c7b","repo":"alibaba/open-code-review","slug":"output-directory-does-not-exist-s","errorCode":null,"errorMessage":"--output directory does not exist: %s","messagePattern":"--output directory does not exist: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared.go","lineNumber":584,"sourceCode":"// cleanup function.\n//   - \"\" or \"-\"      → os.Stdout with a no-op cleanup (colors preserved, no hint)\n//   - otherwise      → a lazyFileWriter over os.Create(path), deferred until the\n//     first Write; text format wraps the file in stripAnsiWriter so ANSI\n//     colors never reach the result file.\n//\n// Fail-fast checks (directory target, missing parent) run here without\n// creating or truncating anything; deeper errors (permissions, disk) surface\n// on the first Write and fail the command non-zero.\nfunc resolveOutputWriter(path, format string) (io.Writer, func() error, error) {\n\tif path == \"\" || path == \"-\" {\n\t\treturn os.Stdout, func() error { return nil }, nil\n\t}\n\tif st, err := os.Stat(path); err == nil && st.IsDir() {\n\t\treturn nil, nil, fmt.Errorf(\"--output %q is a directory\", path)\n\t}\n\tparent := filepath.Dir(path)\n\tif st, err := os.Stat(parent); err != nil || !st.IsDir() {\n\t\treturn nil, nil, fmt.Errorf(\"--output directory does not exist: %s\", parent)\n\t}\n\tw := &lazyFileWriter{path: path, strip: !isMachineReadable(format)}\n\treturn w, w.Close, nil\n}\n\n// ResultProvider abstracts the metadata both internal/agent.Agent and\n// internal/scan.Agent expose post-run, so emitRunResult can finalize\n// either without knowing which kind it has.\ntype ResultProvider interface {\n\tDiffs() []model.Diff\n\tFilesReviewed() int64\n\tTotalInputTokens() int64\n\tTotalOutputTokens() int64\n\tTotalTokensUsed() int64\n\tTotalCacheReadTokens() int64\n\tTotalCacheWriteTokens() int64\n\tWarnings() []agent.AgentWarning\n\t// ProjectSummary is the markdown project-level summary produced by","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared.go#L566-L602","documentation":"resolveOutputWriter validates the --output target before creating a writer. If the parent directory of the requested output path cannot be stat'ed or is not a directory, it refuses to proceed with this error, because writing the review result would fail. The lazyFileWriter defers creation until Close, so a bad parent directory would only surface late; this check fails fast.","triggerScenarios":"Running review/scan with --output set to a path whose parent directory does not exist (e.g. --output reports/ocr.md when ./reports was never created), a parent that is actually a file, or a path under a non-mounted/nonexistent volume. Also covered by tests TestResolveOutputWriter_MissingParent and the anonymous caller.","commonSituations":"Typing a new subdirectory name that was never mkdir'ed, typos in the output path, CI pipelines where the artifacts directory is not pre-created, or pointing output at a path inside a file (e.g. --output docs/README.md/x.md).","solutions":["Create the parent directory first: mkdir -p $(dirname <output-path>)","Verify the output path spelling and that its parent exists and is a directory (ls -ld $(dirname <path>))","Point --output at an existing directory's file path instead of a not-yet-created tree","If the intent was to dump to stdout, omit --output entirely"],"exampleFix":"// before\nocr review --from main --to HEAD --output reports/review.md   # reports/ missing\n// after\nmkdir -p reports && ocr review --from main --to HEAD --output reports/review.md","handlingStrategy":"validation","validationCode":"out=\"reports/review.md\"; dir=$(dirname \"$out\"); if [ ! -d \"$dir\" ]; then mkdir -p \"$dir\" || exit 1; fi; ocr review --from main --to HEAD --output \"$out\"","typeGuard":"null","tryCatchPattern":"if ! ocr review ... --output \"$out\" 2>err.log; then grep -q 'directory does not exist' err.log && { mkdir -p \"$(dirname \"$out\")\"; ocr review ... --output \"$out\"; }; fi","preventionTips":["Always mkdir -p the output parent before invoking ocr","In CI, create the artifacts directory as a pipeline step","Quote and spell-check output paths; avoid paths nested under files","Prefer writing into an existing directory you control"],"tags":["cli","filesystem","output-path"],"backgroundTag":"output-directory-not-found","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}