elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.74k stars 24.68k forks source link

[Painless] Return correct error "end" position #78072

Open sebelga opened 3 years ago

sebelga commented 3 years ago

While integrating the error handling in the Kibana runtime field editor I found an unexpected behaviour with the Painless _executes API error returned.

This the runtime script I provide:

emit('test');
emit(12345678);
emit('test');

And the type is keyword.

I expect it to fail for the emit(12345678) part as I am passing a long and I'd like to be able to underline that part of the script. But the error position that is returned is the following

Screenshot 2021-09-15 at 17 41 46

The offset: 19 is correct as it correspond to the beginning of the 12345678 . But the end is not correct, I would expect 19 + 8 = 27 but instead it indicates end: 43, which is the end of the script and not the end of the error.

As a result this is how the error is underlined in the editor:

Screenshot 2021-09-15 at 17 44 31

Would it be possible to return the end of the error exactly where it ends?

elasticmachine commented 3 years ago

Pinging @elastic/es-core-infra (Team:Core/Infra)