New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Json.Decode.index error messages #928

Closed
cjduncana opened this Issue Dec 15, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@cjduncana

cjduncana commented Dec 15, 2017

If the user of Json.Decode.index provides 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 is undefined: 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:

if (index < 0)
{
     return _Json_expecting('a non-negative index. Index ' + index + ' was provided instead.', value);
}
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

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.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

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.

Member

evancz commented Mar 7, 2018

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.

@evancz evancz closed this Mar 7, 2018

@evancz evancz added the request label Mar 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment