provectus/kafka-ui · error · ValidationException

Script syntax error

Error message

Script syntax error: ${e.getMessage()}

What it means

MessageFilters.compileScript compiles the user's Groovy filter via a GroovyScriptEngineImpl. If the script has Groovy syntax errors, engine.compile throws ScriptException, which is rethrown as ValidationException with the underlying parser message, so the UI can show it to the user.

Solutions

  1. Fix the syntax error reported after 'Script syntax error:' — it includes line/column from Groovy
  2. Balance all braces, parentheses, and string quotes in the script
  3. Test the script in a Groovy console before pasting it into the filter dialog

Example fix

// before (script)
value == null || (value.containsKey('a') && value['a'] > 5
// after (script)
value == null || (value.containsKey('a') && value['a'] > 5)
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check in a Groovy shell before submitting to kafka-ui
def shell = new groovy.lang.GroovyShell()
try { shell.parse(script) } catch (Exception e) { throw new IllegalArgumentException(e.message) }

Try / catch

try {
  const filter = MessageFilters.compile(script);
} catch (ValidationException e) {
  if (e.getMessage().startsWith('Script syntax error:')) {
    displayParserError(e.getMessage()); // includes Groovy line/column details
  }
}

Prevention

When it happens

Trigger: Submitting a filter script with invalid Groovy syntax: unbalanced braces/quotes, reserved words, stray operators, e.g. `value == ` or `if (x { return true }`.

Common situations: Hand-typing complex filters in the small UI dialog; pasting Java-style code that isn't valid Groovy; quotes inside the script colliding with how the value was pasted from JSON/YAML.

Related errors


AI-assisted analysis of provectus/kafka-ui@83b5a60cc0 (2026-09-08). Data as JSON: /api/errors/b5b16b354ef9b688. Report an issue: GitHub.

Appendix: source

Thrown at kafka-ui-api/src/main/java/com/provectus/kafka/ui/emitter/MessageFilters.java:94

    } catch (Exception e) {
      return str;
    }
  }

  private static synchronized GroovyScriptEngineImpl getGroovyEngine() {
    // it is pretty heavy object, so initializing it on-demand
    if (GROOVY_ENGINE == null) {
      GROOVY_ENGINE = (GroovyScriptEngineImpl)
          new ScriptEngineManager().getEngineByName("groovy");
    }
    return GROOVY_ENGINE;
  }

  private static CompiledScript compileScript(GroovyScriptEngineImpl engine, String script) {
    try {
      return engine.compile(script);
    } catch (ScriptException e) {
      throw new ValidationException("Script syntax error: " + e.getMessage());
    }
  }

}

View on GitHub (pinned to 83b5a60cc0)