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

confusing errors for structs with #[serde(flatten)] #22

Open
vthriller opened this issue Mar 6, 2024 · 0 comments
Open

confusing errors for structs with #[serde(flatten)] #22

vthriller opened this issue Mar 6, 2024 · 0 comments

Comments

@vthriller
Copy link

#![allow(dead_code, unused_variables)]
use std::collections::HashMap;

#[derive(Debug, serde::Deserialize)]
struct Config {
    foo: Option<String>,
    #[serde(flatten)]
    other: HashMap<String, usize>,
}

fn main() {
    let src = r#"
    aaa: 1
    bbb: true
    ccc: 3
    ddd: 4
    # and
    # a
    # lot
    # more
    # lines
    foo: bar
    "#;
    
    dbg!(deser_hjson::from_str::<HashMap<String, usize>>(src));
    dbg!(deser_hjson::from_str::<Config>(src));
}

The first message is what I expected to see for both calls to from_str():

[src/main.rs:25:2] deser_hjson::from_str::<HashMap<String, usize>>(src) = Err(
    Syntax {
        line: 3,
        col: 7,
        code: ExpectedU64,
        at: "true\n\tccc: 3\n\td",
    },
)

The second one always seem to point at the last line of the input:

[src/main.rs:26:2] deser_hjson::from_str::<Config>(src) = Err(
    Serde {
        line: 12,
        col: 2,
        message: "invalid type: boolean `true`, expected usize",
    },
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant