Get span information while deserializing with serde?

I'm curious if anyone has ever needed to get span information when deserializing via serde, and if so, what approaches are available?

For a non-serde example showing how span information can be used, imagine you are checking that the links in a Markdown file are valid and come across a potentially undefined link. While you could just print "Warning: Potential incomplete link" and let the user figure it out, it would be much more useful to print something like this:

warning: Potential incomplete link
   ┌─ development/
19 │   - [x] Comments
   │     ^^^ Did you forget to define a URL for `x`?
   = hint: declare the link's URL. For example: `[x]:`

The way we get these nice errors is by using the span, a struct containing the start and end location of an items, then use the surrounding lines and some clever formatting to print human-friendly error messages.

1 Like

I believe serde_path_to_error gets you partway there.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.