Change GeneralScriptException to 400#133659
Merged
rjernst merged 5 commits intoelastic:mainfrom Aug 28, 2025
Merged
Conversation
Errors in scripts are generally due to user errors in the script itself. ScriptException has a 400 status code reflecting that fact, but GeneralScriptException uses the default 500 status code. This commit fixes GeneralScriptException to match the 400 status code of other scripting errors.
Collaborator
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Collaborator
|
Hi @rjernst, I've created a changelog YAML for you. |
javanna
approved these changes
Aug 27, 2025
Contributor
javanna
left a comment
There was a problem hiding this comment.
LGTM
For posterity, we caught this in a scenario where the cause was a circuit breaking exception, whose status code was ignored.
org.elasticsearch.script.GeneralScriptException: Failed to compile inline script [if (doc.containsKey('live_start') && !doc['live_start'].empty && doc.containsKey('live_end') && !doc['live_end'].empty) { long now = 1751987618176L; boolean afterStart = now >= doc['live_start'].value.toInstant().toEpochMilli(); boolean beforeEnd = now < doc['live_end'].value.toInstant().toEpochMilli(); return afterStart && beforeEnd ? 1 : 0; } return 0;] using lang [painless]
at org.elasticsearch.server@9.2.0/org.elasticsearch.script.ScriptCache.compile(ScriptCache.java:120)
at org.elasticsearch.server@9.2.0/org.elasticsearch.script.ScriptService.compile(ScriptService.java:634)
at org.elasticsearch.server@9.2.0/org.elasticsearch.index.query.SearchExecutionContext.compile(SearchExecutionContext.java:581)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.sort.ScriptSortBuilder.fieldComparatorSource(ScriptSortBuilder.java:331)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.sort.ScriptSortBuilder.build(ScriptSortBuilder.java:251)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.sort.SortBuilder.buildSort(SortBuilder.java:161)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.sort.SortBuilder.buildSort(SortBuilder.java:153)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.SearchService.parseSource(SearchService.java:1574)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.SearchService.createContext(SearchService.java:1335)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:869)
at org.elasticsearch.server@9.2.0/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$7(SearchService.java:710)
at org.elasticsearch.server@9.2.0/org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:79)
at org.elasticsearch.server@9.2.0/org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:76)
at org.elasticsearch.server@9.2.0/org.elasticsearch.action.ActionRunnable$4.doRun(ActionRunnable.java:101)
at org.elasticsearch.server@9.2.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)
at org.elasticsearch.server@9.2.0/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:35)
at org.elasticsearch.server@9.2.0/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:1044)
at org.elasticsearch.server@9.2.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1095)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:619)
at java.base/java.lang.Thread.run(Thread.java:1447)
Caused by: org.elasticsearch.common.breaker.CircuitBreakingException: [script] Too many dynamic script compilations within, max: [150/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting
at org.elasticsearch.server@9.2.0/org.elasticsearch.script.ScriptCache.checkCompilationLimit(ScriptCache.java:178)
at org.elasticsearch.server@9.2.0/org.elasticsearch.script.ScriptCache.lambda$compile$0(ScriptCache.java:107)
at org.elasticsearch.server@9.2.0/org.elasticsearch.common.cache.Cache.computeIfAbsent(Cache.java:440)
at org.elasticsearch.server@9.2.0/org.elasticsearch.script.ScriptCache.compile(ScriptCache.java:91)
... 20 more
Another path in that specific case may have been to surface the status code of the root cause perhaps (in that case 429 then), but I am not familiar enough with script exceptions to tell which way is better.
JeremyDahlgren
pushed a commit
to JeremyDahlgren/elasticsearch
that referenced
this pull request
Aug 29, 2025
Errors in scripts are generally due to user errors in the script itself. ScriptException has a 400 status code reflecting that fact, but GeneralScriptException uses the default 500 status code. This commit fixes GeneralScriptException to match the 400 status code of other scripting errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Errors in scripts are generally due to user errors in the script itself. ScriptException has a 400 status code reflecting that fact, but GeneralScriptException uses the default 500 status code. This commit fixes GeneralScriptException to match the 400 status code of other scripting errors.