rumble icon indicating copy to clipboard operation
rumble copied to clipboard

Improve user experience by detecting the typo in query instead of discarding faulty part

Open CanBerker opened this issue 5 years ago • 2 comments

let $fn := function ($a) { $a }
return $fn({
        "k": 2
        "seed": 1
})

Error [err: SENR0001 ] Serialization error; Functions are not serializable.

The query given above has a typo at line 3: the comma is missing after "k": 2. Because of this, the entire object constructor expression and the dynamic functional call are discarded. The query that actually runs looks like this:

let $fn := function ($a) { $a }
return $fn

Hence, it triggers the functions are not serializable error as expected.

I was wondering if we can improve the grammar somehow, so that, instead of running a faulty query and giving a misleading error message, we can give a meaningful error to the user.

Edit: If the original query looks like this (notice the parenthesis around the return expression)

let $fn := function ($a) { $a }
return ($fn({
        "k": 2
        "seed": 1
}))

The following error is given which points to the correct address of the problem: Error [err: XPST0003]LINE:5:COLUMN:14:Parser failed. "seed"

CanBerker avatar Feb 26 '20 23:02 CanBerker

@CanBerker do you still have the issue. I fixed it at least on the shell and checked as well with a query file. It required an explicit EOF in the grammar file.

ghislainfourny avatar Sep 28 '20 13:09 ghislainfourny

Looks much better now, nicely done! image

Feel free to close the issue

CanBerker avatar Sep 30 '20 16:09 CanBerker