ModsToml: Improve error message for invalid files

This commit is contained in:
Juuz
2023-03-17 18:48:29 +02:00
parent 3880902438
commit e37fd9fed2
2 changed files with 17 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableSet;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
import net.fabricmc.loom.util.ExceptionUtil;
public final class ModsToml implements ModMetadataFile {
public static final String FILE_PATH = "META-INF/mods.toml";
@@ -35,7 +36,7 @@ public final class ModsToml implements ModMetadataFile {
try {
return new ModsToml(new TomlParser().parse(text));
} catch (ParsingException e) {
throw new IllegalArgumentException("Could not parse mods.toml", e);
throw ExceptionUtil.createDescriptiveWrapper(IllegalArgumentException::new, "Could not parse mods.toml", e);
}
}
@@ -43,7 +44,7 @@ public final class ModsToml implements ModMetadataFile {
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
return new ModsToml(new TomlParser().parse(reader));
} catch (ParsingException e) {
throw new IllegalArgumentException("Could not parse mods.toml", e);
throw ExceptionUtil.createDescriptiveWrapper(IllegalArgumentException::new, "Could not parse mods.toml", e);
}
}

View File

@@ -24,6 +24,7 @@
package net.fabricmc.loom.test.unit.forge
import com.electronwill.nightconfig.core.io.ParsingException
import dev.architectury.loom.metadata.ModsToml
import spock.lang.Specification
import spock.lang.TempDir
@@ -78,4 +79,17 @@ class ModsTomlTest extends Specification {
then:
modsToml.ids == ['hello', 'world'] as Set
}
def "create from invalid string"() {
given:
def text = '''
[[mods.${MOD_ID}]]
modId = "hello_world"
'''.stripIndent()
when:
ModsToml.of(text)
then:
def e = thrown(IllegalArgumentException)
e.cause instanceof ParsingException
}
}