alibaba/open-code-review · error

--format sarif is not supported with --preview: SARIF output

Error message

--format sarif is not supported with --preview: SARIF output requires completed review findings

What it means

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.

Source

Thrown at cmd/opencodereview/output.go:702

		ag.FilesReviewed(), ag.TotalInputTokens(), ag.TotalOutputTokens(), ag.TotalTokensUsed(),
		toolTotal, duration.Round(time.Second).String(), budgetExceeded)
	if id := ag.SessionID(); id != "" {
		fmt.Fprintf(os.Stderr, ", session %s", id)
	}
	fmt.Fprintln(os.Stderr)
	// Text mode has no structured envelope, so the report follows the usage
	// line on the same stream.
	outputRetryReportText(os.Stderr, retryReport)
}

// outputPreview renders a preview in the requested output format. sarif is
// rejected with an error because a preview contains file/rule metadata, not
// review findings — there is no SARIF result to emit, and a differently-shaped
// document would confuse consumers expecting a SARIF report.
func outputPreview(p *agent.DiffPreview, outputFormat string, out io.Writer) error {
	outputFormat = strings.ToLower(strings.TrimSpace(outputFormat))
	if outputFormat == "sarif" {
		return fmt.Errorf("--format sarif is not supported with --preview: SARIF output requires completed review findings")
	}
	if outputFormat == "json" {
		return outputPreviewJSON(p, out)
	}
	outputPreviewText(p, out)
	// outputPreviewText drops fmt.Fprintf write errors; surface deferred
	// writer errors so a failed --output write fails the command non-zero.
	return writeOutError(out)
}

func outputPreviewJSON(p *agent.DiffPreview, out io.Writer) error {
	enc := json.NewEncoder(out)
	enc.SetIndent("", "  ")
	return enc.Encode(p)
}

func outputPreviewText(p *agent.DiffPreview, out io.Writer) {
	if p.TotalFiles == 0 {

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Drop `--format sarif` when using `--preview`; use the default text output or `--format json` for machine-readable preview output.
  2. If you need SARIF, run the full review (without --preview) so findings exist to emit.
  3. Update CI scripts so preview dry-runs and SARIF-producing full runs use separate flag sets.

Example fix

# before
ocr review --preview --format sarif
# after (dry run)
ocr review --preview --format json
# full run for SARIF
ocr review --format sarif
Defensive patterns

Strategy: validation

Validate before calling

if preview && outputFormat == "sarif" {
    return errors.New("--format sarif is not supported with --preview")
}

Try / catch

if err := runPreview(preview, format); err != nil {
    if strings.Contains(err.Error(), "not supported with --preview") {
        // drop --format sarif or drop --preview and retry
    }
}

Prevention

When it happens

Trigger: 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".

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/6df3a6b200dd2e3c. Report an issue: GitHub.