Skip to content

Commit

Permalink
improve graalvm multi thread errors with reason
Browse files Browse the repository at this point in the history
  • Loading branch information
ake2l committed Mar 17, 2024
1 parent 8192972 commit dc042ce
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/com/rapiddweller/benerator/script/GraalScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ public GraalScript(String text, Engine scriptEngine, String languageId) {
}

@Override
public Object evaluate(Context context) throws ScriptException {
Value returnValue = globalPolyglotCtx.evalScript(context, text, language);
GraalValueConverter converter = new GraalValueConverter();
return converter.convert(returnValue);
public synchronized Object evaluate(Context context) throws ScriptException {
try {
Value returnValue = globalPolyglotCtx.evalScript(context, text, language);
GraalValueConverter converter = new GraalValueConverter();
return converter.convert(returnValue);
} catch (IllegalStateException e) {
if(e.getMessage().contains("Multi threaded access requested")) {
throw new ScriptException(String.format("Multi thread access requested. GraalVM Context is not thread safe. " +
"Please check your script and make sure there is no multi thread access with '%s'", text), null);
}
else {
throw new ScriptException("Error evaluating script: " + text, e);
}
}
}

@Override
Expand Down

0 comments on commit dc042ce

Please sign in to comment.