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

Deserialization errors are less than informative #8

Open
vrurg opened this issue Apr 25, 2024 · 4 comments
Open

Deserialization errors are less than informative #8

vrurg opened this issue Apr 25, 2024 · 4 comments

Comments

@vrurg
Copy link

vrurg commented Apr 25, 2024

As I'm trying to use Gura as my primary app config format, I stumbled upon a problem where deserialization fails due to incorrect structure of the config, but I all I get is an "Expected map" message from ExpectedMap error variant. I'm afraid, it wouldn't be very helpful to a person trying to find out what's wrong with the config. :(

Any chance to extend the reporting with at least full path to the problematic key? Also, I checked out with #5, but found no useful information for myself to help with the problem.

@Genarito
Copy link
Member

Hi @vrurg thanks for reporting!

Could you provide a little example to replicate the problem, please?

@vrurg
Copy link
Author

vrurg commented Apr 25, 2024

Oh, should've done it in first place. A bit overwhelmed and forgot to.

Here is a golfed down variant suitable for rust-script:

//! ```cargo
//! [dependencies]
//! serde = { version = "1.0", features = ["derive"] }
//! serde_gura = "0.1.8"
//! ```
use serde::{Deserialize, Serialize};
use serde_gura;
use std::{collections::HashMap };

#[derive(Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
struct Cfg {
    map: Option<HashMap<String, String>>,
}

fn main() {
    let src = r#"map: "no map""#;

    let cfg = serde_gura::from_str::<Cfg>(src).unwrap();
    println!("{:?}", cfg);
}

It results in a message like this:

called `Result::unwrap()` on an `Err` value: ExpectedMap

@Genarito
Copy link
Member

Genarito commented Apr 26, 2024

Thanks! I'll check and fix it when I have some spare time, maybe during the weekend

Genarito added a commit that referenced this issue May 4, 2024
@Genarito
Copy link
Member

Genarito commented May 7, 2024

Hi @vrurg !

Sorry for the delay, it is taking longer than planned. I already managed to implement the report of which was the expected value in each case, but I would like to be able to report what value is being received and what is the conflicting field. I'm going to have to take ideas from some projects like Serde JSON and take the opportunity to update the tech stack and fix some minor flaws.

Thanks for your patience 🙏

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

2 participants