{"record":{"id":"5f1eb7d3c2f4ae44","repo":"alibaba/open-code-review","slug":"invalid-format-value-q-must-be-text-json","errorCode":null,"errorMessage":"invalid --format value %q: must be 'text', 'json', or 'sarif'","messagePattern":"invalid --format value %q: must be 'text', 'json', or 'sarif'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":120,"sourceCode":"\treturn nil\n}\n\nfunc validateAudience(audience string) error {\n\tswitch audience {\n\tcase \"human\", \"agent\":\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid --audience value %q: must be 'human' or 'agent'\", audience)\n\t}\n}\n\nfunc validateOutputFormat(format string) (string, error) {\n\tnormalized := strings.ToLower(strings.TrimSpace(format))\n\tswitch normalized {\n\tcase \"text\", \"json\", \"sarif\":\n\t\treturn normalized, nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"invalid --format value %q: must be 'text', 'json', or 'sarif'\", format)\n\t}\n}\n\nfunc validateReviewOptions(opts *reviewOptions) error {\n\tif err := validateDiffMode(opts.from, opts.to, opts.commit); err != nil {\n\t\treturn err\n\t}\n\tif opts.preview && opts.resume != \"\" {\n\t\treturn fmt.Errorf(\"--preview and --resume cannot be used together\")\n\t}\n\tif err := validateAudience(opts.audience); err != nil {\n\t\treturn err\n\t}\n\tnormalizedFormat, err := validateOutputFormat(opts.outputFormat)\n\tif err != nil {\n\t\treturn err\n\t}\n\topts.outputFormat = normalizedFormat","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L102-L138","documentation":"validateOutputFormat lowercases and trims --format, then accepts only text, json, or sarif. Anything else returns this error, echoing the original value. The normalized value replaces opts.outputFormat on success.","triggerScenarios":"Passing --format markdown, --format yaml, --format JSON+X, or an empty/whitespace string that fails the switch, from review (validateReviewOptions) or scan (validateScanOptions).","commonSituations":"Users assuming markdown output exists; YAML expectations from other tools; scripts passing a format variable from an unsupported pipeline; machine-readable consumers requesting formats the tool never supported.","solutions":["Use one of --format text, --format json, or --format sarif","If you need markdown, produce it from --format json yourself downstream","Check --help for the supported formats of your installed ocr version","Fix the format variable in your pipeline configuration"],"exampleFix":"// before\nocr review --from main --to HEAD --format markdown\n// after\nocr review --from main --to HEAD --format json","handlingStrategy":"validation","validationCode":"case \"$(echo \"$FORMAT\" | tr '[:upper:]' '[:lower:]')\" in text|json|sarif) ;; *) echo \"invalid format: $FORMAT\"; exit 2;; esac","typeGuard":"function isOutputFormat(v) { return ['text','json','sarif'].includes(String(v).trim().toLowerCase()); }","tryCatchPattern":"ocr review --format \"$FORMAT\" 2>err.log || { grep -q 'invalid --format' err.log && ocr review --format text; }","preventionTips":["Stick to text, json, or sarif (case-insensitive)","Derive downstream artifacts (markdown, etc.) from JSON output instead of requesting it","Pin the format constant in pipeline configuration","Check --help for the version you run"],"tags":["cli","flags","validation","output-format"],"backgroundTag":"invalid-enum-value","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}