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

Move error.position from Error to Reader #1719

Open
dishmaker opened this issue Mar 14, 2025 · 0 comments
Open

Move error.position from Error to Reader #1719

dishmaker opened this issue Mar 14, 2025 · 0 comments

Comments

@dishmaker
Copy link
Contributor

dishmaker commented Mar 14, 2025

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

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