|
23 | 23 | import cpw.mods.jarhandling.SecureJar; |
24 | 24 | import cpw.mods.modlauncher.api.IModuleLayerManager; |
25 | 25 | import cpw.mods.modlauncher.api.NamedPath; |
| 26 | +import org.apache.logging.log4j.LogManager; |
| 27 | +import org.apache.logging.log4j.Logger; |
26 | 28 |
|
27 | 29 | import java.lang.module.Configuration; |
28 | 30 | import java.lang.module.ModuleFinder; |
| 31 | +import java.lang.module.ResolutionException; |
29 | 32 | import java.util.*; |
30 | 33 | import java.util.function.BiFunction; |
31 | 34 | import java.util.function.Consumer; |
32 | 35 |
|
33 | 36 | public final class ModuleLayerHandler implements IModuleLayerManager { |
| 37 | + private static final Logger LOGGER = LogManager.getLogger(); |
34 | 38 | record LayerInfo(ModuleLayer layer, ModuleClassLoader cl) {} |
35 | 39 |
|
36 | 40 | private record PathOrJar(NamedPath path, SecureJar jar) { |
@@ -72,7 +76,15 @@ public LayerInfo buildLayer(final Layer layer, BiFunction<Configuration, List<Mo |
72 | 76 | .map(PathOrJar::build) |
73 | 77 | .toArray(SecureJar[]::new); |
74 | 78 | final var targets = Arrays.stream(finder).map(SecureJar::name).toList(); |
75 | | - final var newConf = Configuration.resolveAndBind(JarModuleFinder.of(finder), Arrays.stream(layer.getParent()).map(completedLayers::get).map(li->li.layer().configuration()).toList(), ModuleFinder.of(), targets); |
| 79 | + final Configuration newConf; |
| 80 | + try { |
| 81 | + newConf = Configuration.resolveAndBind(JarModuleFinder.of(finder), Arrays.stream(layer.getParent()).map(completedLayers::get).map(li -> li.layer().configuration()).toList(), ModuleFinder.of(), targets); |
| 82 | + } catch (ResolutionException e) { |
| 83 | + // Catch and log errors when two mods have the same package name, or other module loading errors |
| 84 | + // This ensures they make it to the log file. |
| 85 | + LOGGER.error("Error while resolving modules.", e); |
| 86 | + throw e; |
| 87 | + } |
76 | 88 | final var allParents = Arrays.stream(layer.getParent()).map(completedLayers::get).map(LayerInfo::layer).<ModuleLayer>mapMulti((moduleLayer, comp)-> { |
77 | 89 | comp.accept(moduleLayer); |
78 | 90 | moduleLayer.parents().forEach(comp); |
|
0 commit comments