mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
ModsToml: Improve error message for invalid files
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user