Skip to content

Enhancement: better error messages for missing struct fields? #393

@maurges

Description

@maurges

Currently missing fields in struct gives no line info, not even the typename info, which makes it hard to find where in the row of same-y declarations you missed a field. For example:

#[derive(serde::Deserialize, Debug)]
struct Test {
    f1: i64,
    f2: String,
}

fn main() {
    let s = r#"
Test (
    f1: 55,
)
"#;
    let x: Result<Test, _> = ron::from_str(s);
    println!("{:?}", x);
}

gives: Err(Error { code: Message("missing field f2"), position: Position { line: 0, col: 0 } })

It would be great if I could get line info, or at least the name "Test" of the record.

Also there is a similar problem with enum variants. Which seems doubly strange, as when I write an incorrect constructor for a struct, like replacing "Test" with "NotTest" in the example above, I get precise error location and type info.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions