Cryptic error UnexpectedStart if serde structs do not match XML
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rust
- Domain
- backend-api-design
Research direction
Start by tracing how quick_xml:🇩🇪:from_str handles a serde struct field whose XML value begins with a nested element, then inspect the error conversion that produces UnexpectedStart. The reproduction uses XmlRoot.generalComment as a String while the XML contains a <text> child. Done means the mismatch returns a more informative error that helps identify the unexpected element; the issue names no test file, so locate or add coverage for this reproduction.
Written by the indexing model from the issue text.
Description
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();
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 299
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tafia/quick-xml
-
Parser accepts an empty element or attribute namePossibly taken @ychampion claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
DecodingReader::set_encoding panics when the XML declaration is longer than 64 bytesPossibly taken @emschwartz claimed this 4 days ago. Openbug encoding
Difficulty 4/5 3-5 days Newbie friendliness 30/100
tafia/quick-xml#1040 · 1 comment ·
Maintainers usually reply within 1 day
-
encoding optimization
Difficulty 4/5 3-5 days Newbie friendliness 55/100
tafia/quick-xml#1039 · 1 comment ·
Maintainers usually reply within 1 day
-
optimization question
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 1-2 days Newbie friendliness 53/100
tafia/quick-xml#1035 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
storytold/photocraft#14822 ·
Maintainers usually reply within 1 day
-
bug css
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dginev/latexml-oxide#853 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 2 days
-
[Bug] export_build_environment admits its output directory only after the export ran in the build computerPossibly taken @viniciusdsandrade claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day