astral-sh/ruff · error
Unsupported serialization format for statistics: {:?}
Error message
Unsupported serialization format for statistics: {:?} What it means
`--statistics` is implemented only for the text formats (full/concise) and json; requesting statistics with any other `--output-format` reaches this bail and names the unsupported format.
Source
Thrown at crates/ruff/src/printer.rs:388
&partially_fixable
} else {
unfixable
}
} else {
""
},
statistic.name,
)?;
}
self.write_summary_text(writer, diagnostics)?;
return Ok(());
}
OutputFormat::Json => {
writeln!(writer, "{}", serde_json::to_string_pretty(&statistics)?)?;
}
_ => {
anyhow::bail!(
"Unsupported serialization format for statistics: {:?}",
self.format
)
}
}
writer.flush()?;
Ok(())
}
pub(crate) fn write_continuously(
&self,
writer: &mut dyn Write,
diagnostics: &Diagnostics,
preview: PreviewMode,
prefer_rule_codes: bool,
) -> Result<()> {View on GitHub (pinned to 672bb4edf0)
Solutions
- Remove --output-format for the statistics run; the default (full) prints text statistics
- Use `ruff check --statistics --output-format json` for machine-readable statistics
- Scope format flags per command instead of globally in CI configuration
Example fix
# before ruff check --statistics --output-format sarif src/ # after ruff check --statistics --output-format json src/
Defensive patterns
Strategy: validation
Validate before calling
case "$fmt" in full|concise|json) ruff check --statistics --output-format "$fmt" "$@" ;; *) echo "--statistics supports only full, concise, or json output" >&2; exit 1 ;; esac
Type guard
fn supports_statistics(format: OutputFormat) -> bool {
matches!(format, OutputFormat::Full | OutputFormat::Concise | OutputFormat::Json)
} Prevention
- Keep --statistics runs in their own CI step without inheriting a global output format
- Use json when statistics must be machine-parsed
- Document in CI config which flags are compatible with each output format
When it happens
Trigger: `ruff check --statistics --output-format sarif` (likewise json-lines, azure, github, gitlab, pylint).
Common situations: CI configs that set a global machine-readable format and then add --statistics; pipelines copied from jobs that never combined the two flags.
Related errors
- Unknown option: {key}
- The `--range` option is only supported when formatting a sin
- {flag} <reason> cannot contain newline characters
- Failed to convert path to URL: {}
- Could not determine source kind for file: {}
AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16).
Data as JSON: /api/errors/20a9dd04b38e86ad.
Report an issue: GitHub.