Skip to content

Commit 674dbab

Browse files
committed
Don't crash when evaluating a non-existing script
1 parent caa277c commit 674dbab

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/main/java/org/cyclops/integratedscripting/core/network/GraalScriptFactory.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ public IScript getScript(int disk, Path path) throws EvaluationException {
4646

4747
try {
4848
// Read script
49-
Source source = Source.newBuilder(this.languageId, ScriptingNetworkHelpers.getScriptingData().getScripts(disk).get(path), path.toString()).build();
49+
String contents = ScriptingNetworkHelpers.getScriptingData().getScripts(disk).get(path);
50+
if (contents == null) {
51+
throw EvaluationExceptionResolutionHelpers.resolveOnScriptChange(
52+
new EvaluationException(Component.translatable("script.integratedscripting.error.script_missing", path.toString(), disk)),
53+
disk, path);
54+
}
55+
Source source = Source.newBuilder(this.languageId, contents, path.toString()).build();
5056
try {
5157
graalContext.eval(source);
5258
} catch (PolyglotException e) {

‎src/main/resources/assets/integratedscripting/lang/en_us.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"script.integratedscripting.error.path_not_in_network": "Disk with id %s does not contain the script \"%s\".",
5858
"script.integratedscripting.error.member_not_in_network": "Disk with id %s does not contain the member \"%s\" in the script \"%s\".",
5959
"script.integratedscripting.error.unsupported_language": "The language of script \"%s\" is not supported.",
60+
"script.integratedscripting.error.script_missing": "The script \"%s\" at disk %s does not exist",
6061
"script.integratedscripting.error.script_read": "An error occurred when reading the script \"%s\" at disk %s: %s",
6162
"script.integratedscripting.error.script_exec": "An error occurred when executing the member \"%s\" in script \"%s\" at disk %s: %s",
6263
"script.integratedscripting.error.invalid_type": "Script with member \"%s\" in script \"%s\" at disk %s is expected to expose a variable with type %s while %s is found.",

0 commit comments

Comments
 (0)