Skip to content

Commit

Permalink
Use better parsing error detection. Fix issue with empty configs retu…
Browse files Browse the repository at this point in the history
…rning null.
  • Loading branch information
OroArmor committed Jan 9, 2024
1 parent b589ded commit 1c81eab
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public Collection<String> repositories() {

@Override
public Collection<String> mixins(EnvType env) {
return this.mixins.get(env);
return this.mixins.getOrDefault(env, Collections.emptyList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ private V1ModMetadataImpl readFields(JsonLoaderValue.ObjectImpl root) {
builder.mixins.computeIfAbsent(EnvType.CLIENT, (env) -> new ArrayList<>()).add(mixinValue.asString());
builder.mixins.computeIfAbsent(EnvType.SERVER, (env) -> new ArrayList<>()).add(mixinValue.asString());
break;
case OBJECT:
readMixin(mixinValue.asObject(), builder.mixins);
break;
default:
throw parseException(mixinValue, "mixin value must be an array of strings or a string");
throw parseException(mixinValue, "mixin value must be a string, a mixin entry, or a mixed array of either");
}
}

Expand Down Expand Up @@ -1017,21 +1020,44 @@ private static void readMixins(JsonLoaderValue.ArrayImpl array, Map<EnvType, Lis
destination.computeIfAbsent(EnvType.SERVER, (env) -> new ArrayList<>()).add(value.asString());
} else if (value.type() == LoaderValue.LType.OBJECT) {
LoaderValue.LObject object = value.asObject();
LoaderValue config = object.get("config");
readMixin(object, destination);
} else {
throw parseException((JsonLoaderValue) value, "Entry inside mixin must be a string or object");
}
}
}

if (config == null) {
throw parseException((JsonLoaderValue) value, "Mixin entry inside must have a config value");
}
LoaderValue environment = object.get("environment");
private static void readMixin(LoaderValue.LObject object, Map<EnvType, List<String>> destination) {
LoaderValue config = object.get("config");

if (config == null) {
throw parseException((JsonLoaderValue) object, "Mixin entry inside must have a config value");
} else if (config.type() != LoaderValue.LType.STRING) {
throw parseException((JsonLoaderValue) object, "Mixin entry config must be a string");
}
LoaderValue environment = object.get("environment");

if (environment == null) {
destination.computeIfAbsent(EnvType.CLIENT, (env) -> new ArrayList<>()).add(config.asString());
destination.computeIfAbsent(EnvType.SERVER, (env) -> new ArrayList<>()).add(config.asString());
} else {
if (environment.type() != LoaderValue.LType.STRING) {
throw parseException((JsonLoaderValue) object, "Mixin entry environment must be a string");
}

if (environment == null) {
switch (environment.asString()) {
case "client":
destination.computeIfAbsent(EnvType.CLIENT, (env) -> new ArrayList<>()).add(config.asString());
break;
case "dedicated_server":
destination.computeIfAbsent(EnvType.SERVER, (env) -> new ArrayList<>()).add(config.asString());
} else {
destination.computeIfAbsent(EnvType.valueOf(environment.asString().toUpperCase()), (env) -> new ArrayList<>()).add(config.asString());
}
} else {
throw parseException((JsonLoaderValue) value, "Entry inside mixins must be a string or object");
break;
case "*":
destination.computeIfAbsent(EnvType.CLIENT, (env) -> new ArrayList<>()).add(config.asString());
destination.computeIfAbsent(EnvType.SERVER, (env) -> new ArrayList<>()).add(config.asString());
break;
default:
throw parseException((JsonLoaderValue) object, "Mixin entry environment must be one of 'client', 'dedicated_server', or '*'");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"config": "mixin4.config.json",
"environment": "server"
"environment": "dedicated_server"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"schema_version": 1,
"quilt_loader": {
"group": "org.example",
"id": "some_id",
"version": "1.0.0",
"intermediate_mappings": "net.fabricmc:intermediary"
},
"mixin": {
"config": "mixin.config.json",
"environment": "client"
}
}

0 comments on commit 1c81eab

Please sign in to comment.