vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

Inconsistent error handling with JsonParser

Open MYDIH opened this issue 3 years ago • 0 comments

Version

4.2.6

Context

I use the JsonParser class to handle a stream of JSON comming from a client request (code follows). When an error is present in the JSON (wrong integer value, additional comma etc ...) everything works as expected, exception handler is called and the code flow continue, the event handler is called with a JSON without the unparseable token (which is fine in my case but maybe weird in others, is it expected/configurable ?). When there is more than one error in the JSON though, the exception handler is called only twice and the json event handler isn't called nor the end handler ...

Do you have a reproducer?

router.post("/test")
        .handler(ctx -> JsonParser.newParser(ctx.request()).objectValueMode()
                .handler(event -> System.out.println("event received"))
                .exceptionHandler(ex -> System.out.println(ex.getMessage()))
                .endHandler(ignored -> { System.out.println("done"); ctx.response().end("done\n"); }));

Steps to reproduce

  1. Run the reproducer in a verticle
  2. Call the road with a payload like {"test":"value"}{"test1":"value1"}{"test2":"value2"}, observe an expected behaviour
  3. Call the road with a payload like {"test":"value"},{"test1":"value1"}{"test2":"value2"}, observe an expected behaviour
  4. Call the road with a payload like {"test":"value"},{"test1":"value1"},{"test2":"value2"}, observe an unexpected behaviour

Extra

jdk11

PS:

I found a work around in the meantime. I could open a PR, but really, I'm not sure it's a good solution, here it is

It introduces some difference between the case where an exception handler is set and the case where it's not, and it's not tested in case of Json input exceeding a single buffer ...

MYDIH avatar Apr 20 '22 06:04 MYDIH