vibe.d icon indicating copy to clipboard operation
vibe.d copied to clipboard

Json error messages can be improved

Open bausshf opened this issue 7 years ago • 3 comments

When you're deserializing json and if you have a misspelling for one of your entries.

Ex. if you have this class:

class Foo { int bar; string test; }

But your json looks like this:

{
    "baz": 0,
    "test": "..."
}

Then you'll get following error message:

std.json.JSONException@.......\vibe-d\data\vibe\data\json.d(1858): Expecting ',' or '}
', not '0'.

But obviously it's not because your json syntax is invalid, but it's because the json entry doesn't match the member of the class you're deserializing to.

That may not be an obvious error if you have large json data.

It's triggered here: https://github.com/vibe-d/vibe.d/blob/2692810e73ac2eb82ebf41af469b9ef7af1847de/data/vibe/data/json.d#L1858

bausshf avatar Oct 23 '17 13:10 bausshf

This isn't even just a bad error message since something like {"baz": 0, "bar": 0, "test": "..."} would fail as well, while it should actually pass. What's missing is a skipValue() that is called when the field name is unknown.

s-ludwig avatar Oct 23 '17 14:10 s-ludwig

This may be related to #1647

HenkKalkwater avatar Jun 30 '21 23:06 HenkKalkwater

Note: There was a PR for it too: https://github.com/vibe-d/vibe.d/pull/1622

Geod24 avatar Jul 01 '21 00:07 Geod24