Improve: serializer/deserializer
Moved from https://github.com/eldesh/dockworker/issues/84#issuecomment-611449910 (@emk)
Thank you for maintaining
dockworker!I'm currently trying to replace
boondockwithdockworkerincage, and I'm hitting this same error.I fought with quite a few of these errors back in the day when working on
boondock, and here's the strategy I used:
- Assume that basically all fields in all structures returned by
dockershould have typeOption<T>, until proven otherwise. There's no internal documentation in thedockersource about what can benulland what can't, and sooner or later, it feels like almost anything can benull.- Centralize all JSON decoding. There should only be one call to
serde_json::from_slicein the library. And it should beserde_json::from_slice, unfortunately, and notserde_json::from_reader, because...- There needs to be some mechanism for automatically logging JSON parse errors with the surrounding context, so that you can see what broke
serde_json. Inboondock, I included the entire JSON blob in the error, but that could be cut down to just show the 30 characters on either side.I would actually love to completely deprecate
boondockin favor ofdockworker, and just submit occasional PRs todockworker. But to do that, there would need to be some kind of mutually agreed-upon solution for (1-3). Would that be of interest to you, if I did the refactoring?
Making the decoding errors richer (solution 3) seems like a good idea.
Solution 1 seems a bit over the top. I would like to fix the bugs that have occurred, in turn.