DioxusLabs/dioxus · error

Syntax Error in line {line} column {column}: {err}

Error message

Syntax Error in line {line} column {column}:
{err}

What it means

dx fmt formats Rust sources by parsing each file with syn::parse_file and re-printing with prettyplease. If a file is not valid Rust, format_rust maps the syn::Error through format_syn_error, producing a message with the 1-based line and column of the error span plus the parser's own description. Formatting of that file aborts and the command returns an error.

Source

Thrown at packages/cli/src/cli/autoformat.rs:255

        tab_spaces,
        split_line_attributes,
    ))
}

/// Format rust code using prettyplease
fn format_rust(input: &str) -> Result<String> {
    let syntax_tree = syn::parse_file(input)
        .map_err(format_syn_error)
        .context("Failed to parse Rust syntax")?;
    let output = prettyplease::unparse(&syntax_tree);
    Ok(output)
}

fn format_syn_error(err: syn::Error) -> Error {
    let start = err.span().start();
    let line = start.line;
    let column = start.column;
    anyhow::anyhow!("Syntax Error in line {line} column {column}:\n{err}")
}

#[tokio::test]
async fn test_auto_fmt() {
    let test_rsx = r#"
                    //



                        div {}


                    //
                    //
                    //

                    "#
    .to_string();

View on GitHub (pinned to 393d190a80)

Solutions

  1. Open the file at the reported line and column and fix the syntax error described in {err}
  2. Run cargo check for the same file to get rustc's fuller diagnostics on the same problem
  3. If the file is generated or disposable, restore it (git checkout) and re-run dx fmt
Defensive patterns

Strategy: validation

Validate before calling

# Fail fast with rustc's diagnostics before dx fmt
cargo check --message-format=short 2>&1 | grep '^error' && echo 'fix syntax first' 

Prevention

When it happens

Trigger: Running dx fmt (autoformat) on a project where at least one .rs file has invalid Rust syntax — unclosed brace, stray token, truncated file. syn::parse_file fails and the span's line/column are reported.

Common situations: A half-saved or merge-conflicted file; generated code with syntax errors; running dx fmt before fixing errors that rust-analyzer/rustc already flagged.

Related errors


AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16). Data as JSON: /api/errors/e671ca29c2bd3bb8. Report an issue: GitHub.