You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are there any plans to better support reporting location information when errors occur? For example, if I try to deserialise 'abc123' as a boolean, it would be great to be able to say what line and column in the stream 'abc123' is on. I've implemented my own solution for the time being but it would be nice if this information was used by the core library and exposed to custom serializers in a consistent way.
I personally think this is highly format-dependent. E.g. binary formats can have only byte offset in a stream, string formats can either have both line and column or only char offset (json can be treated as one big line, and usually unformatted json from rest apis doesn't contain indentation or line breaks). Exceptions also are very likely to be format-specific. Although, it may be possible to commonize an error location (as Location you have), I'm not sure that it will be sufficient for all formats. If you have ideas on how it could be correctly designed, feel free to open a separate issue.
I'm just thinking out loud here, but could there be some very generic Location interface that Decoders can expose (from something like a currentLocation property), and which the engine can then use in exceptions? Then each format could implement something that makes sense - binary formats can give byte offsets and text formats can give line and column information, for example.
These two options could even be included in the runtime itself and formats can then either extend from them if necessary or just add their own.
I haven't spent a lot of time thinking this through, so I'm open to other ideas and feedback :)
The text was updated successfully, but these errors were encountered:
This reverts commit 51a8e25.
Having access to YamlInput is useful for custom serializers to be able
to get location information when reporting errors, and until
Kotlin/kotlinx.serialization#316 is resolved,
there's no other way to do this.
I ended up implementing this in Kaml - exceptions have location (line and column) and path (eg. users[2].name) information, and this is also accessible to custom serializers. The implementation isn't perfect, but it could be useful inspiration for what broader support in kotlinx.serialization could look like.
Continuing the discussion from #309:
@charleskorn:
@sandwwraith:
I'm just thinking out loud here, but could there be some very generic
Location
interface thatDecoder
s can expose (from something like acurrentLocation
property), and which the engine can then use in exceptions? Then each format could implement something that makes sense - binary formats can give byte offsets and text formats can give line and column information, for example.These two options could even be included in the runtime itself and formats can then either extend from them if necessary or just add their own.
I haven't spent a lot of time thinking this through, so I'm open to other ideas and feedback :)
The text was updated successfully, but these errors were encountered: