{"record":{"id":"59a6849b98382faf","repo":"ast-grep/ast-grep","slug":"diagnosticerror","errorCode":"DiagnosticError","errorMessage":"DiagnosticError(error_count)","messagePattern":"DiagnosticError\\(error_count\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/scan.rs","lineNumber":197,"sourceCode":"      max_item_counter,\n    })\n  }\n}\nimpl Worker for ScanWithConfig {\n  fn consume_items<P: Printer>(\n    &self,\n    items: Items<P::Processed>,\n    mut printer: P,\n  ) -> Result<ExitCode> {\n    printer.before_print()?;\n    for item in items {\n      printer.process(item)?;\n    }\n    printer.after_print()?;\n    self.trace.print()?;\n    let error_count = self.error_count.load(Ordering::Acquire);\n    if error_count > 0 {\n      Err(anyhow::anyhow!(EC::DiagnosticError(error_count)))\n    } else {\n      Ok(ExitCode::SUCCESS)\n    }\n  }\n}\n\n// we should only suggest unused suppression if scan includes all rules\n// otherwise, keep silent about unused suppressions because they may used by other rules\n// this is a \"smart\" heuristic but user always can override it\nfn default_unused_suppression_rule_severity(arg: &ScanArg) -> Severity {\n  if arg.include_all_rules() {\n    Severity::Hint\n  } else {\n    Severity::Off\n  }\n}\n\nfn no_suppress_all_rule_config(overwrite: &RuleOverwrite) -> RuleConfig<SgLang> {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/ast-grep/ast-grep/blob/fc2b1530db74de49131b725221de98036a552a9f/crates/cli/src/scan.rs#L179-L215","documentation":"The `scan` command collects diagnostics (parse errors of scanned files, rule compile errors, etc.) in an atomic counter while printing matches. After scanning completes, if any diagnostics were recorded, scan exits with DiagnosticError(error_count) instead of success, so CI pipelines fail when input files could not be fully analyzed.","triggerScenarios":"Running `sg scan` where any processed file produced a diagnostic — e.g. a scanned file failed to parse under its inferred language, or a rule config emitted a diagnostic — and the worker's consume_items sees error_count > 0 after printing.","commonSituations":"Scanning directories that contain intentionally-invalid code (minified files, fixtures, snippets in docs); a rule whose transformations error on some files; committing fixture directories without ignore rules.","solutions":["Exclude the problematic files/dirs via .gitignore or the `sgconfig.yml` globs so they are not scanned","Fix or skip rules that emit diagnostics on valid input files","Check the printed diagnostics to see which files errored and repair or remove them","If diagnostics are expected, run scan with output inspected rather than fail-on-error gating"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const code = sh('sg scan .', { nothrow: true }); if (code.status !== 0 && /DiagnosticError/.test(code.stderr)) { console.warn('scan had diagnostics:', code.stderr); }","preventionTips":["Keep generated/vendored dirs in .gitignore","Scope scan to source directories","Fix rules that error on valid input"],"tags":["cli","ast-grep","scan","diagnostics"],"backgroundTag":"scan-diagnostics-failed","analyzedSha":"fc2b1530db74de49131b725221de98036a552a9f","analyzedAt":"2026-09-05T18:06:27.540Z","contentChangedAt":"2026-09-05T18:06:27.540Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}