mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-04-12 18:30:26 +08:00
Remove SilentException
This commit is contained in:
parent
ed66b016db
commit
b22e724a3f
@ -20,17 +20,18 @@ package org.jackhuang.hmcl.ui;
|
||||
import com.jfoenix.utils.JFXUtilities;
|
||||
import org.jackhuang.hmcl.auth.Account;
|
||||
import org.jackhuang.hmcl.auth.AuthInfo;
|
||||
import org.jackhuang.hmcl.auth.AuthenticationException;
|
||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||
import org.jackhuang.hmcl.task.SilentException;
|
||||
import org.jackhuang.hmcl.ui.account.AccountLoginPane;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class DialogController {
|
||||
|
||||
public static AuthInfo logIn(Account account) throws Exception {
|
||||
public static AuthInfo logIn(Account account) throws CancellationException, AuthenticationException, InterruptedException {
|
||||
if (account instanceof YggdrasilAccount) {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<AuthInfo> res = new AtomicReference<>(null);
|
||||
@ -42,7 +43,7 @@ public final class DialogController {
|
||||
Controllers.dialog(pane);
|
||||
});
|
||||
latch.await();
|
||||
return Optional.ofNullable(res.get()).orElseThrow(SilentException::new);
|
||||
return Optional.ofNullable(res.get()).orElseThrow(CancellationException::new);
|
||||
}
|
||||
return account.logIn();
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import static org.jackhuang.hmcl.util.Lang.thread;
|
||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AccountListItem extends RadioButton {
|
||||
@ -84,6 +85,8 @@ public class AccountListItem extends RadioButton {
|
||||
} catch (CredentialExpiredException e) {
|
||||
try {
|
||||
DialogController.logIn(account);
|
||||
} catch (CancellationException e1) {
|
||||
// ignore cancellation
|
||||
} catch (Exception e1) {
|
||||
LOG.log(Level.WARNING, "Failed to refresh " + account + " with password", e1);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.jackhuang.hmcl.mod;
|
||||
|
||||
import org.jackhuang.hmcl.game.DefaultGameRepository;
|
||||
import org.jackhuang.hmcl.task.SilentException;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
|
||||
@ -49,11 +48,6 @@ public class ModpackUpdateTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRelyingOnDependencies() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Task> getDependencies() {
|
||||
return Collections.singleton(updateTask);
|
||||
@ -78,8 +72,6 @@ public class ModpackUpdateTask extends Task {
|
||||
repository.removeVersionFromDisk(id);
|
||||
|
||||
FileUtils.copyDirectory(backupFolder, repository.getVersionRoot(id).toPath());
|
||||
|
||||
throw new SilentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher
|
||||
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.jackhuang.hmcl.task;
|
||||
|
||||
/**
|
||||
* If a task throws {@link SilentException},
|
||||
* the task will be marked as failure but do not log the stacktrace.
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public final class SilentException extends Exception {
|
||||
|
||||
}
|
@ -33,6 +33,7 @@ import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
@ -154,8 +155,15 @@ public abstract class Task {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called after dependency tasks terminated all together.
|
||||
*
|
||||
* You can check whether dependencies succeed in this method by calling
|
||||
* {@link Task#isDependenciesSucceeded()} no matter when
|
||||
* {@link Task#isRelyingOnDependencies()} returns true or false.
|
||||
*
|
||||
* @throws InterruptedException if current thread is interrupted
|
||||
* @see Thread#isInterrupted
|
||||
* @see Task#isDependenciesSucceeded()
|
||||
*/
|
||||
public void postExecute() throws Exception {}
|
||||
|
||||
@ -370,8 +378,13 @@ public abstract class Task {
|
||||
public void execute() throws Exception {
|
||||
action.execute(isDependentsSucceeded(), Task.this.getLastException());
|
||||
|
||||
if (!isDependentsSucceeded())
|
||||
throw new SilentException();
|
||||
if (!isDependentsSucceeded()) {
|
||||
setSignificance(TaskSignificance.MINOR);
|
||||
if (Task.this.getLastException() == null)
|
||||
throw new CancellationException();
|
||||
else
|
||||
throw Task.this.getLastException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,7 +163,7 @@ public final class TaskExecutor {
|
||||
Exception dependentsException = dependents.stream().map(Task::getLastException).filter(Objects::nonNull).findAny().orElse(null);
|
||||
if (!doDependentsSucceeded && task.isRelyingOnDependents() || canceled) {
|
||||
task.setLastException(dependentsException);
|
||||
throw new SilentException();
|
||||
throw new CancellationException();
|
||||
}
|
||||
|
||||
if (doDependentsSucceeded)
|
||||
@ -187,11 +187,6 @@ public final class TaskExecutor {
|
||||
Collection<? extends Task> dependencies = task.getDependencies();
|
||||
boolean doDependenciesSucceeded = executeTasks(dependencies);
|
||||
Exception dependenciesException = dependencies.stream().map(Task::getLastException).filter(Objects::nonNull).findAny().orElse(null);
|
||||
if (!doDependenciesSucceeded && task.isRelyingOnDependencies()) {
|
||||
Logging.LOG.severe("Subtasks failed for " + task.getName());
|
||||
task.setLastException(dependenciesException);
|
||||
throw new SilentException();
|
||||
}
|
||||
|
||||
if (doDependenciesSucceeded)
|
||||
task.setDependenciesSucceeded();
|
||||
@ -207,6 +202,12 @@ public final class TaskExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
if (!doDependenciesSucceeded && task.isRelyingOnDependencies()) {
|
||||
Logging.LOG.severe("Subtasks failed for " + task.getName());
|
||||
task.setLastException(dependenciesException);
|
||||
throw new CancellationException();
|
||||
}
|
||||
|
||||
flag = true;
|
||||
if (task.getSignificance().shouldLog()) {
|
||||
Logging.LOG.log(Level.FINER, "Task finished: " + task.getName());
|
||||
@ -221,8 +222,9 @@ public final class TaskExecutor {
|
||||
}
|
||||
task.onDone().fireEvent(new TaskEvent(this, task, true));
|
||||
taskListeners.forEach(it -> it.onFailed(task, e));
|
||||
} catch (SilentException | RejectedExecutionException e) {
|
||||
task.setLastException(e);
|
||||
} catch (CancellationException | RejectedExecutionException e) {
|
||||
if (task.getLastException() == null)
|
||||
task.setLastException(e);
|
||||
} catch (Exception e) {
|
||||
task.setLastException(e);
|
||||
lastException = e;
|
||||
|
Loading…
x
Reference in New Issue
Block a user