tink_json icon indicating copy to clipboard operation
tink_json copied to clipboard

confusing error message for wrong variable type.

Open kobi2187 opened this issue 8 years ago • 2 comments

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!

kobi2187 avatar Jan 17 '17 12:01 kobi2187

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

kevinresol avatar Jan 17 '17 15:01 kevinresol

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.

back2dos avatar Jan 17 '17 16:01 back2dos