Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Properly propagate exception to sentinel mod (close #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz authored and ustc-zzzz committed Aug 9, 2022
1 parent 53258a7 commit e3d04c3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/org/teacon/sync/SyncedModLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.teacon.sync;

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import cpw.mods.modlauncher.Launcher;
import cpw.mods.modlauncher.api.IEnvironment;
import net.minecraftforge.fml.loading.moddiscovery.AbstractJarFileLocator;
Expand All @@ -46,6 +47,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.function.Consumer;
import java.util.stream.Stream;

Expand Down Expand Up @@ -86,15 +88,15 @@ public SyncedModLocator() throws Exception {
LOGGER.warn("Failed to download mod list", e);
throw new RuntimeException(e);
}
}).handleAsync((fcModList, exc) -> {
if (exc != null) {
return new ModEntry[0];
}
}).thenApplyAsync((fcModList) -> {
try (Reader reader = Channels.newReader(fcModList, "UTF-8")) {
return GSON.fromJson(reader, ModEntry[].class);
} catch (JsonParseException e) {
LOGGER.warn("Error parsing modlist", e);
throw e;
} catch (IOException e) {
LOGGER.warn("Failed to fetch mod list from remote", e);
return new ModEntry[0];
throw new RuntimeException(e);
}
}).thenComposeAsync(entries -> {
var futures = Arrays.stream(entries).flatMap(e -> Stream.of(
Expand Down Expand Up @@ -130,7 +132,7 @@ public Stream<Path> scanCandidates() {
return this.fetchPathsTask.join().stream();
} catch (Exception e) {
LOGGER.error("Mod downloading worker encountered error and cannot continue. " +
"No mod will be loaded from the remote-synced locator. ", e);
"No mod will be loaded from the remote-synced locator. ", e instanceof CompletionException ? e.getCause() : e);
System.setProperty("org.teacon.sync.failed", "true");
return Stream.empty();
}
Expand Down

0 comments on commit e3d04c3

Please sign in to comment.