Skip to content

der: Move error.position from Error to Reader #1719

Open
@dishmaker

Description

@dishmaker

Currently, it is annoying to track error.position in every function returning der::Error.

From another issue:

Attempting to even construct der::Error was confusing [...] It is also unclear to me whether the position that this method uses will be correct [...]

formats/der/src/error.rs

Lines 23 to 24 in 9813667

/// Position inside of message where error occurred.
position: Option<Length>,

Actually, most functions don't return the position - example:

|| !(0..=23).contains(&hour)
|| !(0..=59).contains(&minutes)
|| !(0..=59).contains(&seconds)
{
return Err(ErrorKind::DateTime.into());

What I suggest is something like serde + quick-xml:

let mut reader = SliceReader::new(EXAMPLE_MSG).unwrap();
let err = SomeStruct::decode(&mut reader);
assert!(err.is_err());

assert_eq!(reader.error_position(), 28);

https://docs.rs/quick-xml/latest/quick_xml/de/struct.Deserializer.html#method.get_ref

tafia/quick-xml#743

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions