include key in error message from getField functions #44
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.
What does this pull request do?
Extends the error message returned in the
Left
result ofgetField
andgetFieldOptional
. This will take the message coming fromdecodeJson
and prepend it with a helpful message that includes the specific key that failed to decode (e.g.Value is not a String
will becomeFailed to decode 'foo': Value is not a String
).How should this be manually tested?
All tests are still passing, and this doesn't change the API in any way. To manually test you could create a
Json
value with a type that doesn't match what it should and see the new error on decode.Other Notes:
This is a very simple change that will go a long way toward making the decoding error messages more useful, however a more robust solution akin to Aeson Better Errors would be ideal. For now though, I think this should be good.