Skip to content

Enhancement: Better ParseError #221

@JRAndreassen

Description

@JRAndreassen

Hi...

Love the crate...
I'd love it even more if the from_str() gave better error messages.

When I parse a file with serde I often get:

Failed: "Custom { field: \"Matching variant not found\" }"

It would be ooohhh so much better if it said:

Failed: Custom { field: \"Matching variant not found: [EnumName:'Value']\" }"

Perhaps change:

pub enum ParseError {
    VariantNotFound(String),
}

...
    fn from_str( s: &str,    ) ...
{
...
        _ => ::core::result::Result::Err(::strum::ParseError::VariantNotFound(format!("StructName[{}]", s))),
}

I know it's extra overhead, but ohhh so useful.
Could make it optional and/or only in Test/Debug
Since serde does not always give a good error, even with serde_path_to_error...

Thanks
JR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions