Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Painless Script Single Line Comment at EOF Causes Parsing Error #11815

Closed
camerondurham opened this issue Jan 9, 2024 · 0 comments · Fixed by #11816
Closed

[BUG] Painless Script Single Line Comment at EOF Causes Parsing Error #11815

camerondurham opened this issue Jan 9, 2024 · 0 comments · Fixed by #11816
Labels
bug Something isn't working Other v2.12.0 Issues and PRs related to version 2.12.0 v3.0.0 Issues and PRs related to version 3.0.0

Comments

@camerondurham
Copy link
Contributor

camerondurham commented Jan 9, 2024

Describe the bug

The Painless language as implemented has a papercut that scripts cannot end in a single-line comment without a newline/carriage-return.

Was there a specific motivation why EOF wasn't a valid end token for single-line comments?

If so, it could be helpful to document that as leaving a comment without newline leads to an un-intuitive error: "type":"illegal_argument_exception","reason":"unexpected character [/ I am an unparsable comment].","caused_by":{"type":"lexer_no_viable_alt_exception","reason":null

If not, then suggesting a change to the lexer/grammar (like #11816)

Related component

Other

From my understanding, this is actually a bug from when this was forked from ElasticSearch, based on this definition of a comment: https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-comments.html

To Reproduce

docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" public.ecr.aws/opensearchproject/opensearch:2.11.1

# wait for single-node cluster to init

curl -ku 'admin:admin' -XGET "https://localhost:9200/_scripts/painless/_execute" -H 'Content-Type: application/json' -d'{ 
    "script": 
        { 
            "source": "return 5 // I am an unparsable comment" 
        } 
}'


{"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["return 5 // I am an unparsable comm ...","          ^---- HERE"],"script":"return 5 // I am an unparsable comment","lang":"painless","position":{"offset":10,"start":0,"end":35}}],"type":"script_exception","reason":"compile error","script_stack":["return 5 // I am an unparsable comm ...","          ^---- HERE"],"script":"return 5 // I am an unparsable comment","lang":"painless","position":{"offset":10,"start":0,"end":35},"caused_by":{"type":"illegal_argument_exception","reason":"unexpected character [/ I am an unparsable comment].","caused_by":{"type":"lexer_no_viable_alt_exception","reason":null}}},"status":400}%

Expected behavior

Comments at EOF without newline do not

curl -ku 'admin:admin' -XGET "https://localhost:9200/_scripts/painless/_execute" -H 'Content-Type: application/json' -d' { "script": { "source": "return 5 // I am an unparsable comment" } }'
{"result":"5"}

Additional Details

Plugins
Please list all plugins currently enabled.:

N/A NONE

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: Linux (from Docker Desktop for Mac)
  • Version 2.11.1

Additional context
Add any other context about the problem here.

@camerondurham camerondurham added bug Something isn't working untriaged labels Jan 9, 2024
@github-actions github-actions bot added the Other label Jan 9, 2024
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
…ect#11815

Signed-off-by: Cameron Durham <camdurha@amazon.com>
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
camerondurham added a commit to camerondurham/OpenSearch that referenced this issue Jan 9, 2024
dblock pushed a commit that referenced this issue Jan 10, 2024
* Single line comments can end in newline or EOF. Fixes #11815

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Re-add license to autogen parser files

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Remove noise from changelog

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

* Accept single-line comments until newline char

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

---------

Signed-off-by: camerondurham <u64.cam@gmail.com>
Signed-off-by: Cameron Durham <u64.cam@gmail.com>
opensearch-trigger-bot bot pushed a commit that referenced this issue Jan 10, 2024
* Single line comments can end in newline or EOF. Fixes #11815

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Re-add license to autogen parser files

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Remove noise from changelog

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

* Accept single-line comments until newline char

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

---------

Signed-off-by: camerondurham <u64.cam@gmail.com>
Signed-off-by: Cameron Durham <u64.cam@gmail.com>
(cherry picked from commit 8192488)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@reta reta added v3.0.0 Issues and PRs related to version 3.0.0 v2.12.0 Issues and PRs related to version 2.12.0 and removed untriaged labels Jan 10, 2024
reta pushed a commit that referenced this issue Jan 10, 2024
…#11834)

* Single line comments can end in newline or EOF. Fixes #11815



* Re-add license to autogen parser files



* Remove noise from changelog



* Accept single-line comments until newline char



---------



(cherry picked from commit 8192488)

Signed-off-by: camerondurham <u64.cam@gmail.com>
Signed-off-by: Cameron Durham <u64.cam@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
rayshrey pushed a commit to rayshrey/OpenSearch that referenced this issue Mar 18, 2024
…ect#11815 (opensearch-project#11816)

* Single line comments can end in newline or EOF. Fixes opensearch-project#11815

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Re-add license to autogen parser files

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Remove noise from changelog

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

* Accept single-line comments until newline char

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

---------

Signed-off-by: camerondurham <u64.cam@gmail.com>
Signed-off-by: Cameron Durham <u64.cam@gmail.com>
shiv0408 pushed a commit to Gaurav614/OpenSearch that referenced this issue Apr 25, 2024
…ect#11815 (opensearch-project#11816)

* Single line comments can end in newline or EOF. Fixes opensearch-project#11815

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Re-add license to autogen parser files

Signed-off-by: camerondurham <u64.cam@gmail.com>

* Remove noise from changelog

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

* Accept single-line comments until newline char

Signed-off-by: Cameron Durham <u64.cam@gmail.com>

---------

Signed-off-by: camerondurham <u64.cam@gmail.com>
Signed-off-by: Cameron Durham <u64.cam@gmail.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Other v2.12.0 Issues and PRs related to version 2.12.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants