This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
Implement better path and type reporting in error messages #219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #165
This PR improves the error messaging in
Unbox
to show the full path through the JSON being parsed so that it's obvious where the error is happening.This implementation differs slightly from the one proposed in that issue, in that it uses plain dot syntax for array indices instead of subscripting (
thing.2.property
instead ofthing[2].property
). It shouldn't be hard to change this if subscripting is desired, but I used dot syntax to stay in sync with unbox's keypath syntax for querying into arrays, which looks like it uses dot syntax.I've also added type information to some of the errors, so that if there's a type unboxing error, you can know exactly what types are being used and add the appropriate protocol conformances to make them work if the JSON data is correct.
Tests have also been added for all the cases I could think of that exercise these new error enhancements.
I hope this helps! Let me know if there's any issues. I'd love to get this integrated quickly :)