Skip to content

Commit 6dd3020

Browse files
committed
guess that "Module.print is not a function" means out of memory
Signed-off-by: Stefan Niederhauser <[email protected]>
1 parent adb04db commit 6dd3020

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

graphviz-java/src/main/java/guru/nidi/graphviz/engine/GraphvizV8Engine.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package guru.nidi.graphviz.engine;
1717

18-
import com.eclipsesource.v8.*;
18+
import com.eclipsesource.v8.V8;
19+
import com.eclipsesource.v8.V8RuntimeException;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122

@@ -78,10 +79,16 @@ private static class Env implements AutoCloseable {
7879
LOG.info("Started V8 runtime. Initializing graphviz...");
7980
v8.executeVoidScript(viz);
8081
v8.executeVoidScript(init);
81-
v8.registerJavaMethod((JavaVoidCallback) (receiver, parameters) ->
82-
resultHandler.setResult(parameters.getString(0)), "result");
83-
v8.registerJavaMethod((JavaVoidCallback) (receiver, parameters) ->
84-
resultHandler.setError(parameters.getString(0)), "error");
82+
v8.registerJavaMethod((receiver, parameters) -> {
83+
resultHandler.setResult(parameters.getString(0));
84+
}, "result");
85+
v8.registerJavaMethod((receiver, parameters) -> {
86+
final String rawMsg = parameters.getString(0);
87+
final String msg = rawMsg.matches("TypeError: Module\\..*? is not a function")
88+
? "Got Error: '" + rawMsg + "'. This is probably an out of memory error. Try using the totalMemory method."
89+
: rawMsg;
90+
resultHandler.setError(msg);
91+
}, "error");
8592
LOG.info("Initialized graphviz.");
8693
}
8794

0 commit comments

Comments
 (0)