haxetink / tink_json

Macro powered JSON.
The Unlicense
34 stars 9 forks source link

confusing error message for wrong variable type. #8

Open kobi2187 opened 7 years ago

kobi2187 commented 7 years ago

When I supplied a typedef with wrong types, to be the parsing result for Json.parse function I got the following exception.

Uncaught exception - Error#422: 
Expected " at character 30 in ... :true,"data":[{"id": ----> 9 <---- 225,"creator_user_id ... @ tink.json.BasicParser.die:237

An example for a better error message can be:

IN array 'data', item's field 'id:String' should be 'id:Int' to match '9' 
line was:  .....

Thanks!

kevinresol commented 7 years ago

another way is to "lint" it. For example, rethinkdb does sth like this:

Database 'my_db' does not exist
r.db('my_db').table('my table');
^^^^^^^^^^^^^

So it uses the symbol ^ to point out the erroneous portion. But it could be challenging to deal with line breaks if the source is long.

yet another way is to show the drilled path like "data[0].id" should be Int

back2dos commented 7 years ago

I'm not sure just how far I want to go with this. The library is built with speed in mind, so there are limits to just how much context we can carry around. That said just creating errors at lexeme level and throwing them in the user's face with just the single character source is way too brutal. There's certainly enough information at compile time to get something like String literal expected but found <actualExpr> using skipValue to extract actualExpr and using the whole skipped expression's position to report the error. Or something.