DioxusLabs/dioxus · error

Failed to format file

Error message

Failed to format file

What it means

`fmt_file` is the deprecated panic-on-error formatter; it calls `syn::parse_file` and `expect`s success. This panic fires when the given source cannot be parsed as valid Rust. The deprecation note points users to `try_fmt_file`, which returns the error instead.

Source

Thrown at packages/autofmt/src/lib.rs:46

pub struct FormattedBlock {
    /// The new contents of the block
    pub formatted: String,

    /// The line number of the first line of the block.
    pub start: usize,

    /// The end of the block, exclusive.
    pub end: usize,
}

/// Format a file into a list of `FormattedBlock`s to be applied by an IDE for autoformatting.
///
/// It accepts
#[deprecated(note = "Use try_fmt_file instead - this function panics on error.")]
pub fn fmt_file(contents: &str, indent: IndentOptions) -> Vec<FormattedBlock> {
    let parsed =
        syn::parse_file(contents).expect("fmt_file should only be called on valid syn::File files");
    try_fmt_file(contents, &parsed, indent).expect("Failed to format file")
}

/// Format a file into a list of `FormattedBlock`s to be applied by an IDE for autoformatting.
///
/// This function expects a complete file, not just a block of code. To format individual rsx! blocks, use fmt_block instead.
///
/// The point here is to provide precise modifications of a source file so an accompanying IDE tool can map these changes
/// back to the file precisely.
///
/// Nested blocks of RSX will be handled automatically
///
/// This returns an error if the rsx itself is invalid.
///
/// Will early return if any of the expressions are not complete. Even though we *could* return the
/// expressions, eventually we'll want to pass off expression formatting to rustfmt which will reject
/// those.
pub fn try_fmt_file(
    contents: &str,

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Check the file for syntax errors that prevent formatting, and ensure rustfmt-compatible input; inspect the underlying error for details.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/autofmt/src/lib.rs:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/e82f681155db75bf. Report an issue: GitHub.