Skip to content

Commit a4bd5aa

Browse files
committed
When JS engine is not available report helpful error message
1 parent 7e327eb commit a4bd5aa

File tree

1 file changed

+5
-1
lines changed
  • core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/shacl/constraint

1 file changed

+5
-1
lines changed

core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/shacl/constraint/JsConstraint.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public JsConstraint( final String message, final JsLibrary jsLibrary, final Stri
7575
// See https://www.graalvm.org/22.3/reference-manual/js/FAQ/#warning-implementation-does-not-support-runtime-compilation
7676
System.setProperty( "polyglot.engine.WarnInterpreterOnly", "false" );
7777
engine = new ScriptEngineManager().getEngineByName( "JavaScript" );
78+
if ( engine == null ) {
79+
throw new ShaclValidationException( "Could not initialize JavaScript engine. Please make sure org.graalvm.js:js is "
80+
+ "in the list of dependencies and/or the 'js' component is installed in you GraalVM runtime." );
81+
}
7882
final Bindings bindings = engine.getBindings( ScriptContext.ENGINE_SCOPE );
7983
// The following settings are required to allow the script to access methods and fields on the injected objects
8084
bindings.put( "polyglot.js.allowHostAccess", true );
@@ -111,7 +115,7 @@ public List<Violation> apply( final RDFNode rdfNode, final EvaluationContext con
111115
try {
112116
final Object this_ = JsFactory.asJsTerm( context.element().asNode() );
113117
final Object value = JsFactory.asJsTerm( rdfNode.asNode() );
114-
final Object result = ((Invocable) engine).invokeFunction( jsFunctionName, this_, value );
118+
final Object result = ( (Invocable) engine ).invokeFunction( jsFunctionName, this_, value );
115119
if ( result == null ) {
116120
return List.of( new JsConstraintViolation( context, "JavaScript evaluation of " + jsFunctionName() + " returned null",
117121
jsLibrary(), jsFunctionName(), Collections.emptyMap() ) );

0 commit comments

Comments
 (0)