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

Catch some loading errors #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions loader/src/main/java/net/neoforged/fml/loading/ModSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ private ModSorter(final List<ModFile> modFiles)
this.uniqueModListBuilder = new UniqueModListBuilder(modFiles);
}

public static LoadingModList sort(List<ModFile> mods, final List<EarlyLoadingException.ExceptionData> errors)
public static LoadingModList sort(List<ModFile> mods, final List<EarlyLoadingException.ExceptionData> discoveryError)
{
final ModSorter ms = new ModSorter(mods);
// If a discovery error was encountered, abort
if (!discoveryError.isEmpty()) {
return ms.buildSystemMods(new EarlyLoadingException("encountered discovery error", null, discoveryError));
}

try {
ms.buildUniqueList();
} catch (EarlyLoadingException e) {
// We cannot build any list with duped mods. We have to abort immediately and report it
return LoadingModList.of(ms.systemMods, ms.systemMods.stream().map(mf->(ModInfo)mf.getModInfos().get(0)).collect(toList()), e);
return ms.buildSystemMods(e);
}

// try and validate dependencies
Expand All @@ -60,7 +65,7 @@ public static LoadingModList sort(List<ModFile> mods, final List<EarlyLoadingExc

// if we miss a dependency or detect an incompatibility, we abort now
if (!resolutionResult.versionResolution.isEmpty() || !resolutionResult.incompatibilities.isEmpty()) {
list = LoadingModList.of(ms.systemMods, ms.systemMods.stream().map(mf->(ModInfo)mf.getModInfos().get(0)).collect(toList()), new EarlyLoadingException("failure to validate mod list", null, resolutionResult.buildErrorMessages()));
list = ms.buildSystemMods(new EarlyLoadingException("failure to validate mod list", null, resolutionResult.buildErrorMessages()));
} else {
// Otherwise, lets try and sort the modlist and proceed
EarlyLoadingException earlyLoadingException = null;
Expand All @@ -83,6 +88,10 @@ public static LoadingModList sort(List<ModFile> mods, final List<EarlyLoadingExc
return list;
}

public LoadingModList buildSystemMods(EarlyLoadingException exception) {
return LoadingModList.of(systemMods, systemMods.stream().map(mf -> (ModInfo) mf.getModInfos().get(0)).toList(), exception);
}

@SuppressWarnings("UnstableApiUsage")
private void sort()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class AbstractModProvider implements IModProvider
{
Expand All @@ -43,10 +45,15 @@ protected IModLocator.ModFileOrException createMod(Path... path) {
type = getDefaultJarModType();
}
if (jarContents.findFile(MODS_TOML).isPresent()) {
LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MODS_TOML, type, path);
var mjm = new ModJarMetadata(jarContents);
mod = new ModFile(SecureJar.from(jarContents, mjm), this, ModFileParser::modsTomlParser);
mjm.setModFile(mod);
try {
LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MODS_TOML, type, path);
var mjm = new ModJarMetadata(jarContents);
mod = new ModFile(SecureJar.from(jarContents, mjm), this, ModFileParser::modsTomlParser);
mjm.setModFile(mod);
} catch (InvalidModFileException invalidModException) {
LOGGER.error("Mod at [{}] has an invalid mod file: ", Stream.of(path).map(p -> p.toAbsolutePath().toString()).collect(Collectors.joining(", ")), invalidModException);
return new IModLocator.ModFileOrException(null, invalidModException);
}
} else if (type != null) {
LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MANIFEST, type, path);
mod = new ModFile(SecureJar.from(jarContents), this, this::manifestParser, type);
Expand Down
Loading