Cryptic error UnexpectedStart if serde structs do not match XML

Abierto
#834 0 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
rust

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

serde

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();
Lenguaje dominante
Rust
Estrellas
1.6k
Forks
299
Merge medio
2 d 4 h
PR fusionados (30 d)
9

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tafia/quick-xml

Todos los issues de tafia/quick-xml

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.