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

Add ability to get spans of deserialized values #695

Open
Trolldemorted opened this issue Dec 10, 2023 · 4 comments
Open

Add ability to get spans of deserialized values #695

Trolldemorted opened this issue Dec 10, 2023 · 4 comments
Labels
enhancement help wanted serde Issues related to mapping from Rust types to XML

Comments

@Trolldemorted
Copy link

In one of my projects I have to parse and strictly validate XML input coming from other programs and humans, and the latter (understandably) insist on getting decent error messages (e.g. "at 'position' attribute X references an object called 'Y' which is not defined anywhere", "unexpected child Z at 'position', allowed child items are A,B and C").

As of now I use roxmltree and codespan-reporting, but I'd love to switch to an xml library with derivation support - you can imagine a lot of code could be substituted with just using quick-xml.

To satisfy the "nice error messages" requirement I need the precise locations of everything, though. I have scrolled through the deserialization docs, but could not find any mention of access to positions when using deserialization. Did I miss anything or is this not possible right now? Could you expose the offset in the input through e.g. generated getters?

@Mingun Mingun added duplicate serde Issues related to mapping from Rust types to XML labels Dec 11, 2023
@Mingun
Copy link
Collaborator

Mingun commented Dec 11, 2023

Currently this is not implemented and it is already tracked in #313. Contributions are welcomed!

@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
@Trolldemorted
Copy link
Author

Trolldemorted commented Dec 11, 2023

#313 is about lines of code for deserialization errors, this is about lines of code for successful deserializations - even if quick-xml successfully parses e.g. a string attribute, I must be able to raise an error if the string is unexpected

@Mingun
Copy link
Collaborator

Mingun commented Dec 11, 2023

That's generally impossible without changes in serde, because you cannot get any meta-information from the deserializer generically. Actually, I tried to implement this but that required changes in serde and I outlined the solution here: serde-rs/serde#2420 (comment).

I do not see any good solutions here. If you could implement one, make a PR.

@Mingun Mingun reopened this Dec 11, 2023
@Mingun Mingun changed the title Position propagation for the serialize feature Add ability to get spans of deserialized values Dec 11, 2023
@Trolldemorted
Copy link
Author

Trolldemorted commented Jan 14, 2024

I have found https://github.com/toml-rs/toml/blob/main/crates/serde_spanned/src/spanned.rs but I don't know enough about the serde ecosystem to give you a concise summary how it works, or whether their approach is feasible for quick-xml.

Bugs with certain scenarios do appear to exist though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants