{"record":{"id":"6df3a6b200dd2e3c","repo":"alibaba/open-code-review","slug":"format-sarif-is-not-supported-with-preview-sa","errorCode":null,"errorMessage":"--format sarif is not supported with --preview: SARIF output requires completed review findings","messagePattern":"--format sarif is not supported with --preview: SARIF output requires completed review findings","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/output.go","lineNumber":702,"sourceCode":"\t\tag.FilesReviewed(), ag.TotalInputTokens(), ag.TotalOutputTokens(), ag.TotalTokensUsed(),\n\t\ttoolTotal, duration.Round(time.Second).String(), budgetExceeded)\n\tif id := ag.SessionID(); id != \"\" {\n\t\tfmt.Fprintf(os.Stderr, \", session %s\", id)\n\t}\n\tfmt.Fprintln(os.Stderr)\n\t// Text mode has no structured envelope, so the report follows the usage\n\t// line on the same stream.\n\toutputRetryReportText(os.Stderr, retryReport)\n}\n\n// outputPreview renders a preview in the requested output format. sarif is\n// rejected with an error because a preview contains file/rule metadata, not\n// review findings — there is no SARIF result to emit, and a differently-shaped\n// document would confuse consumers expecting a SARIF report.\nfunc outputPreview(p *agent.DiffPreview, outputFormat string, out io.Writer) error {\n\toutputFormat = strings.ToLower(strings.TrimSpace(outputFormat))\n\tif outputFormat == \"sarif\" {\n\t\treturn fmt.Errorf(\"--format sarif is not supported with --preview: SARIF output requires completed review findings\")\n\t}\n\tif outputFormat == \"json\" {\n\t\treturn outputPreviewJSON(p, out)\n\t}\n\toutputPreviewText(p, out)\n\t// outputPreviewText drops fmt.Fprintf write errors; surface deferred\n\t// writer errors so a failed --output write fails the command non-zero.\n\treturn writeOutError(out)\n}\n\nfunc outputPreviewJSON(p *agent.DiffPreview, out io.Writer) error {\n\tenc := json.NewEncoder(out)\n\tenc.SetIndent(\"\", \"  \")\n\treturn enc.Encode(p)\n}\n\nfunc outputPreviewText(p *agent.DiffPreview, out io.Writer) {\n\tif p.TotalFiles == 0 {","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/output.go#L684-L720","documentation":"Raised by outputPreview when a user combines `--preview` with `--format sarif`. A preview contains file/rule metadata only — no completed review findings — so there is no SARIF result array to emit; producing a differently-shaped SARIF document would break consumers expecting a valid report, so the combination is rejected outright.","triggerScenarios":"Running a preview-mode command (e.g. `ocr review --preview` or scan preview) with `--format sarif`, or any call path through outputPreview with outputFormat normalized to \"sarif\".","commonSituations":"Scripting SARIF uploads into code-scanning pipelines and reusing the same flags with --preview to dry-run; CI jobs templated from full-review invocations but run in preview mode.","solutions":["Drop `--format sarif` when using `--preview`; use the default text output or `--format json` for machine-readable preview output.","If you need SARIF, run the full review (without --preview) so findings exist to emit.","Update CI scripts so preview dry-runs and SARIF-producing full runs use separate flag sets."],"exampleFix":"# before\nocr review --preview --format sarif\n# after (dry run)\nocr review --preview --format json\n# full run for SARIF\nocr review --format sarif","handlingStrategy":"validation","validationCode":"if preview && outputFormat == \"sarif\" {\n    return errors.New(\"--format sarif is not supported with --preview\")\n}","typeGuard":null,"tryCatchPattern":"if err := runPreview(preview, format); err != nil {\n    if strings.Contains(err.Error(), \"not supported with --preview\") {\n        // drop --format sarif or drop --preview and retry\n    }\n}","preventionTips":["Treat --preview as a dry-run that only supports text/json output.","Keep SARIF output in full-review CI jobs, separate from preview commands.","Validate flag combinations in CI scripts before rollout."],"tags":["cli","output-format","sarif","flag-combination"],"backgroundTag":"incompatible-flag-combination","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}