Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error when node is not present #160

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;

public class LiteralLoader<T> extends OptionLoader {

private final Class<T> typeClass;

public LiteralLoader(String key, Class<T> typeClass, boolean multiple, boolean optional) {
Expand Down Expand Up @@ -38,7 +39,13 @@ public boolean loadEntry(SectionConfiguration config, FileElement element, Parse
if (isMultiple()) {
List<T> 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.
Expand All @@ -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) {
Expand All @@ -62,5 +74,7 @@ public boolean loadEntry(SectionConfiguration config, FileElement element, Parse
config.getData().put(key, result);
return true;
}

}

}
Loading