{"record":{"id":"c9c7e9f21dd87781","repo":"alibaba/open-code-review","slug":"emit-review-result-w","errorCode":null,"errorMessage":"emit review result: %w","messagePattern":"emit review result: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/review_cmd.go","lineNumber":289,"sourceCode":"\t\t// its invariant failure must not change the review's exit status.\n\t\tfmt.Fprintf(os.Stderr, \"[ocr] warning: freeze retry report: %v (retry report suppressed)\\n\", freezeErr)\n\t}\n\n\tresultErr := reviewResultError(runErr, manifest)\n\tif resultErr != nil {\n\t\tspan.SetStatus(codes.Error, resultErr.Error())\n\t\tspan.RecordError(resultErr)\n\t}\n\n\t// A successfully constructed manifest is publishable even when execution or\n\t// session delivery failed. Emit it first, then return the independent process\n\t// error so JSON consumers retain the complete coverage diagnosis.\n\tvar emitErr error\n\temitted := manifest != nil || runErr == nil\n\tif emitted {\n\t\temitErr = emitRunResult(runCtx, ag, comments, startTime, opts.outputFormat, opts.audience, q, llmIdentity, out, retryReport)\n\t\tif emitErr != nil {\n\t\t\temitErr = fmt.Errorf(\"emit review result: %w\", emitErr)\n\t\t}\n\t}\n\tif resultErr != nil {\n\t\tq.Restore()\n\t\t// The report has exactly one exit per run. emitRunResult already published\n\t\t// it whenever it ran (which it does even for a fully failed run, since a\n\t\t// failed manifest is still publishable), so the failure-usage path gets it\n\t\t// only when that call was skipped entirely.\n\t\tfailureReport := retryReport\n\t\tif emitted {\n\t\t\tfailureReport = nil\n\t\t}\n\t\temitFailureUsage(ag, time.Since(startTime), opts.outputFormat, llmIdentity, failureReport)\n\t\tif id := ag.SessionID(); id != \"\" {\n\t\t\tfmt.Fprintf(os.Stderr, \"[ocr] Session: %s (retry with: --resume %s)\\n\", id, id)\n\t\t}\n\t\treturn errors.Join(resultErr, emitErr)\n\t}","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/review_cmd.go#L271-L307","documentation":"Writing the run manifest/review result (JSON output) failed after execution. The design intentionally emits the manifest even when the run itself failed, so consumers always receive coverage data; this error means that emit step itself failed (serializer or writer error). It is joined with the result error so both are reported.","triggerScenarios":"Thrown at cmd/opencodereview/review_cmd.go:289 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error to see why emitting the manifest failed (invalid output writer, serialization error, closed stream)","If using --output, verify the target path is writable","The manifest is emitted before the process error is returned so JSON consumers keep the full diagnosis; re-run with output to stderr or a valid file"],"exampleFix":null,"handlingStrategy":"try-catch","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"}