elastic/elasticsearch · error · GeneralScriptException
Error running {template}
Error message
Error running {template} What it means
Thrown by MustacheExecutableScript.execute() as a catch-all for any exception during template rendering that is not a size-limit violation and not a missing-parameter error. The original exception is wrapped in a GeneralScriptException with the template's toString() representation. If shouldLogException() returns true (cause exists and is not MustacheInvalidParameterException), the error is also logged at ERROR level before throwing.
Source
Thrown at modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java:158
this.template = template;
this.params = params;
}
@Override
public String execute() {
StringWriter writer = new SizeLimitingStringWriter(sizeLimit);
try {
template.execute(writer, params);
} catch (Exception e) {
// size limit exception can appear at several places in the causal list depending on script & context
if (ExceptionsHelper.unwrap(e, SizeLimitingStringWriter.SizeLimitExceededException.class) != null) {
// don't log, client problem
throw new ElasticsearchParseException("Mustache script result size limit exceeded", e);
}
if (shouldLogException(e)) {
logger.error(() -> format("Error running %s", template), e);
}
throw new GeneralScriptException("Error running " + template, e);
}
return writer.toString();
}
public boolean shouldLogException(Throwable e) {
return e.getCause() != null && e.getCause() instanceof MustacheInvalidParameterException == false;
}
}
}
View on GitHub (pinned to db6a809a66)
Solutions
- Check the server logs for the full stack trace — the ERROR log entry includes the underlying cause
- Validate all parameter types match what the template expects (strings, numbers, arrays, maps)
- Test the template with minimal parameters first, then add complexity incrementally to isolate the failing input
- If the cause is a MustacheException from encoding, see the specific encoding error documentation
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate parameter types before template execution
void validateTemplateParams(Map<String, Object> params, Set<String> required) {
for (String key : required) {
if (!params.containsKey(key)) {
throw new IllegalArgumentException("Missing required param: " + key);
}
}
// check for null values that could cause NPEs during rendering
params.forEach((k, v) -> {
if (v == null) log.warn("Param [{}] is null — may cause rendering error", k);
});
} Try / catch
// Catch GeneralScriptException at the call site
try {
String result = script.execute();
} catch (GeneralScriptException e) {
// check server logs for full stack trace logged at ERROR level
log.error("Template execution failed: {}", e.getMessage(), e);
// inspect e.getCause() for the root failure
} Prevention
- Validate all parameter types match template expectations before execution
- Avoid null parameter values unless the template handles them
- Check server ERROR logs for the full stack trace of the underlying cause
- Test templates with minimal parameters first, then add complexity incrementally
When it happens
Trigger: Any runtime failure during template.execute() that doesn't match the size-limit or missing-param patterns. This includes encoding failures (error 1244), JSON conversion failures (1250), URL encoding failures (1252), null pointer exceptions during rendering, or any unexpected mustache library internal error. The template variable in the message is the Mustache object's toString().
Common situations: Passing null or incompatible parameter types that cause failures during rendering. Template logic errors like accessing nested properties on null values. Underlying encoder or serializer failures. The root cause is in the wrapped exception — check server logs for the full stack trace.
Related errors
- Unable to encode value
- No encoder found for media type [{}]
- Cannot expand '%s' because partial templates are not support
- Cannot expand '%s' because dynamic partial templates are not
- Mustache function [{}] must contain one and only one identif
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/41d9d610a560c436.
Report an issue: GitHub.