Skip to content

if parse error happens at end-of-line, no span is given #234

Description

@duckinator

E.g., when implementing YAML support, this testcase fails because more content is expected after goodbye:, so it points at column 9... in an 8-column line.

I feel like it'd still be useful to show that information.

#[test]
#[cfg(feature = "yaml-serde")]
fn yaml_invalid() {
    use axoasset::AxoassetError;

    #[derive(serde::Deserialize, PartialEq, Eq, Debug)]
    struct MyType {
        hello: String,
        goodbye: bool,
    }

    // Make the file
    let contents = String::from(
        r##"
hello: "there"
goodbye:
"##,
    );
    let source = axoasset::SourceFile::new("file.yml", contents);

    let res = source.deserialize_yaml::<MyType>();
    assert!(res.is_err());
    println!("{:#?}", res);
    let Err(AxoassetError::Yaml { span: Some(_), .. }) = res else {
        panic!("span was invalid");
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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