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

  1. Remove --output-format for the statistics run; the default (full) prints text statistics
  2. Use `ruff check --statistics --output-format json` for machine-readable statistics
  3. 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

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


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/20a9dd04b38e86ad. Report an issue: GitHub.