{"record":{"id":"27879de86173b762","repo":"DioxusLabs/dioxus","slug":"fmt-file-should-only-be-called-on-valid-syn-file","errorCode":null,"errorMessage":"fmt_file should only be called on valid syn::File files","messagePattern":"fmt_file should only be called on valid syn::File files","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/autofmt/src/lib.rs","lineNumber":45,"sourceCode":"#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, PartialEq, Eq, Hash)]\npub struct FormattedBlock {\n    /// The new contents of the block\n    pub formatted: String,\n\n    /// The line number of the first line of the block.\n    pub start: usize,\n\n    /// The end of the block, exclusive.\n    pub end: usize,\n}\n\n/// Format a file into a list of `FormattedBlock`s to be applied by an IDE for autoformatting.\n///\n/// It accepts\n#[deprecated(note = \"Use try_fmt_file instead - this function panics on error.\")]\npub fn fmt_file(contents: &str, indent: IndentOptions) -> Vec<FormattedBlock> {\n    let parsed =\n        syn::parse_file(contents).expect(\"fmt_file should only be called on valid syn::File files\");\n    try_fmt_file(contents, &parsed, indent).expect(\"Failed to format file\")\n}\n\n/// Format a file into a list of `FormattedBlock`s to be applied by an IDE for autoformatting.\n///\n/// This function expects a complete file, not just a block of code. To format individual rsx! blocks, use fmt_block instead.\n///\n/// The point here is to provide precise modifications of a source file so an accompanying IDE tool can map these changes\n/// back to the file precisely.\n///\n/// Nested blocks of RSX will be handled automatically\n///\n/// This returns an error if the rsx itself is invalid.\n///\n/// Will early return if any of the expressions are not complete. Even though we *could* return the\n/// expressions, eventually we'll want to pass off expression formatting to rustfmt which will reject\n/// those.\npub fn try_fmt_file(","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/autofmt/src/lib.rs#L27-L63","documentation":"Deprecated fmt_file panics when the input source cannot be parsed by syn — i.e. the caller passed Rust code that is not syntactically valid. The replacement try_fmt_file returns this as a Result instead.","triggerScenarios":"Thrown at packages/autofmt/src/lib.rs:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only call fmt_file with content that parses as a complete Rust file (syn::File); for fragments, format them within a full file or use the appropriate fragment API."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}