Skip to content

Commit

Permalink
[1.9.2] Option to rethrow LaunchExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
3arthqu4ke committed Apr 1, 2024
1 parent 0c06ed1 commit a737289
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package me.earth.headlessmc.command;

import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;
import lombok.val;
import me.earth.headlessmc.api.HeadlessMc;
import me.earth.headlessmc.api.command.Command;
import me.earth.headlessmc.api.command.CommandContext;
import me.earth.headlessmc.api.command.CommandException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.*;

import static me.earth.headlessmc.command.CommandUtil.levenshtein;

@RequiredArgsConstructor
@SuppressWarnings({"unchecked", "RedundantSuppression"}) // delegate
public class CommandContextImpl implements CommandContext {
@Delegate(types = Iterable.class)
protected final List<Command> commands = new ArrayList<>();
protected final HeadlessMc log;

Expand Down Expand Up @@ -72,4 +67,9 @@ protected void fail(String... args) {
}
}

@Override
public Iterator<Command> iterator() {
return commands.iterator();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ public interface LauncherProperties extends HmcProperties {

Property<String> FABRIC_URL = string("hmc.fabric.url");
Property<Boolean> OFFLINE = bool("hmc.offline");
Property<Boolean> RE_THROW_LAUNCH_EXCEPTIONS = bool("hmc.rethrow.launch.exceptions");

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.IOException;
import java.util.UUID;

import static me.earth.headlessmc.launcher.LauncherProperties.RE_THROW_LAUNCH_EXCEPTIONS;

@CustomLog
public class LaunchCommand extends AbstractVersionCommand {
public LaunchCommand(Launcher launcher) {
Expand Down Expand Up @@ -70,6 +72,9 @@ public void execute(Version version, String... args)
e.printStackTrace();
ctx.log(String.format(
"Couldn't launch %s: %s", version.getName(), e.getMessage()));
if (ctx.getConfig().get(RE_THROW_LAUNCH_EXCEPTIONS, false)) {
throw new RuntimeException(e);
}
} catch (Throwable t) {
val msg = String.format(
"Couldn't launch %s: %s", version.getName(), t.getMessage());
Expand Down

0 comments on commit a737289

Please sign in to comment.