Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upImproving Json.Decode.index error messages #928
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Dec 15, 2017
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Dec 15, 2017
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Mar 7, 2018
Member
The next release should make it easier to create custom error messages. Having lots of special cases by default will increase code size in ways that is not right for everyone, so I would not want to commit everyone to this approach.
|
The next release should make it easier to create custom error messages. Having lots of special cases by default will increase code size in ways that is not right for everyone, so I would not want to commit everyone to this approach. |
cjduncana commentedDec 15, 2017
If the user of
Json.Decode.indexprovides a negative integer, the following error message is decoded:Err "Expecting an Int at _[-1] but instead got: undefined"(Example). Though technically correct we have an opportunity to improve the error message since we know why that position isundefined: a negative number was provided.My suggestion is to check before this and this if the integer provided is less than zero. If so, then provide a helpful error message like in the case when the integer exceeds the array's length:
Err "Expecting a longer array. Need index 5 but there are only 3 entries but instead got: [1,2,3]"(Example).Sample code: