Skip to content

Cryptic error UnexpectedStart if serde structs do not match XML #834

@GeeWee

Description

@GeeWee

Hi! I'm using quick_xml to deserialize to some serde structs. While I'm still developing the structs against the XML, it happens that I have mismatches between my structs and the XML. If that happens instead of getting an error like "Expected type X at location Y", I get a pretty cryptic error, specifically:

called `Result::unwrap()` on an `Err` value: UnexpectedStart([116, 101, 120, 116])

Which doesn't give me much information to start debugging, about where the issue is, or even what it is.

A real-life-inspired reproduction that creates this error is as follows:

    let xml = r#"
<?xml version='1.0' encoding='UTF-8'?>
    <outerTag>
        <generalComment>
              <text xml:lang="en" index="0">some text</text>
        </generalComment>
    </outerTag>
    "#;

    #[derive(Deserialize)]
    pub struct XmlRoot {
       // Oops you thought this was a string but it's not
        generalComment: String,
    }

    // Error: Unexpected start
    let result = quick_xml::de::from_str::<XmlRoot>(xml).unwrap();

Metadata

Metadata

Assignees

No one assigned

    Labels

    serdeIssues related to mapping from Rust types to XML

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions