astral-sh/ruff · error · anyhow::Error

Unsupported serialization format for statistics

Error message

Unsupported serialization format for statistics: {:?}

What it means

The statistics printer only supports serialization to text-style output formats and JSON. If the configured `--output-format` cannot serialize diagnostics statistics (e.g. `full`, `concise`, or other human-only formats), the printer bails instead of silently misformatting output.

Solutions

  1. Use `--output-format=json` when you need machine-readable statistics.
  2. Use `--output-format=text` (or drop `--output-format`) for the default human-readable statistics table.
  3. Separate the statistics run from the diagnostics run instead of sharing one output-format flag.

Example fix

// before
ruff check --statistics --output-format=full src/
// after
ruff check --statistics --output-format=json src/
Defensive patterns

Strategy: validation

Validate before calling

# Only use JSON or text output format with --statistics:
if '--statistics' in flags and output_format not in (None, 'text', 'json'):
    raise SystemExit(f'--output-format={output_format} is unsupported for statistics')

Prevention

When it happens

Trigger: Running a command that emits statistics (e.g. `ruff check --statistics`) with an unsupported `--output-format` such as `full` or `concise`, hitting the catch-all arm in `Printer::write_statistics`.

Common situations: CI scripts combining `--statistics` with an output format meant for diagnostics; users copying output-format flags between different ruff subcommands; config files setting a global output format that conflicts with `--statistics`.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/20a9dd04b38e86ad. Report an issue: GitHub.

Appendix: 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 26f38c119c)