From 139997f764a61dd9fdeaba477763162b54af8746 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 23 Mar 2024 06:30:06 -0600 Subject: [PATCH] Add error when node is not present (#160) --- .../lang/entries/LiteralLoader.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/syst3ms/skriptparser/lang/entries/LiteralLoader.java b/src/main/java/io/github/syst3ms/skriptparser/lang/entries/LiteralLoader.java index 12343fe6..37c5293a 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/lang/entries/LiteralLoader.java +++ b/src/main/java/io/github/syst3ms/skriptparser/lang/entries/LiteralLoader.java @@ -10,6 +10,7 @@ import java.util.List; public class LiteralLoader extends OptionLoader { + private final Class typeClass; public LiteralLoader(String key, Class typeClass, boolean multiple, boolean optional) { @@ -38,7 +39,13 @@ public boolean loadEntry(SectionConfiguration config, FileElement element, Parse if (isMultiple()) { List data = new ArrayList<>(); boolean successful = true; - for (var value : config.getStringList(key).orElse(new String[0])) { + + var list = config.getStringList(key); + if (!list.isPresent()) { + logger.error("List at key '" + key + "' does not exist.", ErrorType.SEMANTIC_ERROR); + return false; + } + for (var value : list.get()) { var result = parser.apply(value); if (result == null) { // With the logic that errors get skipped, we will allow the other values to be parsed. @@ -52,7 +59,12 @@ public boolean loadEntry(SectionConfiguration config, FileElement element, Parse config.getData().put(key, data.toArray()); return successful; } else { - var result = parser.apply(config.getString(key).orElseThrow()); + var value = config.getString(key); + if (!value.isPresent()) { + logger.error("Key '" + key + "' does not exist.", ErrorType.SEMANTIC_ERROR); + return false; + } + var result = parser.apply(value.get()); // We don't want this data to linger if an error occurs config.getData().remove(key); if (result == null) { @@ -62,5 +74,7 @@ public boolean loadEntry(SectionConfiguration config, FileElement element, Parse config.getData().put(key, result); return true; } + } + }