Finding error in STON string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Finding error in STON string

Peter Uhnak
Would be possible for STON to report context for error?
For example

STON fromString: '[
"first",
"second",
]'

reports "At character 23: invalid input" which is not very useful especially in longer strings.
(at: 23 is actually Character cr)

Maybe better would be something like

'At character 23: invalid input near "second", ]' so I already see the surrounding text (this is not perfect, but I find it very common for example to forget comma when moving things around in array.

Or even better, allow comma after the last item.
(Arguably even JSON (unlike JavaScript) doesn't allow this so maybe it would break stuff.)

Peter
Reply | Threaded
Open this post in threaded view
|

Re: Finding error in STON string

Sven Van Caekenberghe-2

> On 05 Jul 2015, at 14:19, Peter Uhnák <[hidden email]> wrote:
>
> Would be possible for STON to report context for error?
> For example
>
> STON fromString: '[
> "first",
> "second",
> ]'
>
> reports "At character 23: invalid input" which is not very useful especially in longer strings.
> (at: 23 is actually Character cr)
>
> Maybe better would be something like
>
> 'At character 23: invalid input near "second", ]' so I already see the surrounding text (this is not perfect, but I find it very common for example to forget comma when moving things around in array.

Yes, the error handling is not very human oriented.

You could show the context yourself, showing input 10 positions before and after the indicated position where the parsing failed.

> Or even better, allow comma after the last item.
> (Arguably even JSON (unlike JavaScript) doesn't allow this so maybe it would break stuff.)

Like you said yourself, not a good idea.

> Peter