Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GeeWee opened this issue Dec 13, 2024 · 0 comments
Open

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

GeeWee opened this issue Dec 13, 2024 · 0 comments
Labels
serde Issues related to mapping from Rust types to XML

Comments

@GeeWee
Copy link

GeeWee commented Dec 13, 2024

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();
@GeeWee GeeWee changed the title Cryptic error UnexpectedStart if schema does not match Cryptic error UnexpectedStart if serde structs do not match XML Dec 13, 2024
@Mingun Mingun added the serde Issues related to mapping from Rust types to XML label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants