jansson icon indicating copy to clipboard operation
jansson copied to clipboard

Friendly error

Open JoakimSoderberg opened this issue 10 years ago • 9 comments

This is a proof of concept for printing a helper "error indicator" discussed in #153

I made it so that you get the buffer back in this implementation, but a simple print function could be done as well. And I'm not sure if we should use malloc or not?

I added a use in the simple_parser test program for an easy way to test it with different input.

Example output:

Type some JSON > {["a","b","c",]}
Error:
{["a","b","c",]
  ^~~~~~ (string or '}' expected near '[')

JoakimSoderberg avatar Jan 14 '15 22:01 JoakimSoderberg

In my opinion using malloc is OK. Another option would be to use a user-supplied buffer, but it's somewhat harder to use.

I'll add diff comments next.

akheron avatar Jan 15 '15 05:01 akheron

Coverage Status

Coverage decreased (-2.81%) when pulling bde5513649b2146d0af65fcf08ebf77746d7eddb on JoakimSoderberg:friendly_error into 58c188e1d5967a1d905acce9beb450204d7da56b on akheron:master.

coveralls avatar Jan 16 '15 13:01 coveralls

Hmm so I guess assuming that column was bytes, not utf-8 code points was dumb :) int column The column on which the error occurred. Note that this is the character column, not the byte column, i.e. a multibyte UTF-8 character counts as one column. RTFM

JoakimSoderberg avatar Jan 16 '15 15:01 JoakimSoderberg

Hmm. Even I didn't remember very well, then :)

But if the column already is characters and the console supports UTF-8, should you just print an arrow whose length is the same as column? For example U+00E4 (ä) is \xc3\xa4 when encoded as UTF-8, but (per Jansson's documentation) the column only increments by one in this case.

akheron avatar Jan 21 '15 05:01 akheron

What's the status of this? IIRC there were some problems with characters vs. bytes which are not very easy to get right, am I correct?

akheron avatar Mar 07 '15 07:03 akheron

Ah yes, sorry... I kind of lost the steam, my focus has been on this lately: https://github.com/JoakimSoderberg/cargo Inspired by python argparse :)

I will try to get to this eventually.

JoakimSoderberg avatar Mar 07 '15 12:03 JoakimSoderberg

Ok, no hurry. cargo looks cool :)

akheron avatar Mar 08 '15 05:03 akheron

I'd appreciate this too, using JSON for config files means hand editing and more error info makes that much easier. But sorry, I don't have time to actually work on the code.

MozLe avatar May 03 '15 22:05 MozLe

@JoakimSoderberg any chance we might see this PR resolved soon? Like MozLe above, I'm also using JSON for config files, and this would be very useful.

Zer0-One avatar Dec 18 '15 10:12 Zer0-One