mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-18 16:26:05 -04:00
remove lastException in task.variables
This commit is contained in:
parent
3ae826d9ca
commit
e57180eb15
@ -106,7 +106,7 @@ public class AddAuthlibInjectorServerPane extends StackPane implements DialogAwa
|
|||||||
|
|
||||||
Task.of(() -> {
|
Task.of(() -> {
|
||||||
serverBeingAdded = AuthlibInjectorServer.locateServer(url);
|
serverBeingAdded = AuthlibInjectorServer.locateServer(url);
|
||||||
}).finalized(Schedulers.javafx(), (variables, isDependentsSucceeded) -> {
|
}).finalized(Schedulers.javafx(), (variables, isDependentsSucceeded, exception) -> {
|
||||||
addServerPane.setDisable(false);
|
addServerPane.setDisable(false);
|
||||||
nextPane.hideSpinner();
|
nextPane.hideSpinner();
|
||||||
|
|
||||||
@ -118,7 +118,6 @@ public class AddAuthlibInjectorServerPane extends StackPane implements DialogAwa
|
|||||||
|
|
||||||
transitionHandler.setContent(confirmServerPane, ContainerAnimations.SWIPE_LEFT.getAnimationProducer());
|
transitionHandler.setContent(confirmServerPane, ContainerAnimations.SWIPE_LEFT.getAnimationProducer());
|
||||||
} else {
|
} else {
|
||||||
Exception exception = variables.get("lastException");
|
|
||||||
LOG.log(Level.WARNING, "Failed to resolve auth server: " + url, exception);
|
LOG.log(Level.WARNING, "Failed to resolve auth server: " + url, exception);
|
||||||
lblCreationWarning.setText(resolveFetchExceptionMessage(exception));
|
lblCreationWarning.setText(resolveFetchExceptionMessage(exception));
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public final class VanillaInstallWizardProvider implements WizardProvider {
|
|||||||
if (settings.containsKey("optifine"))
|
if (settings.containsKey("optifine"))
|
||||||
builder.version((RemoteVersion) settings.get("optifine"));
|
builder.version((RemoteVersion) settings.get("optifine"));
|
||||||
|
|
||||||
return builder.buildAsync().finalized((a, b) -> profile.getRepository().refreshVersions())
|
return builder.buildAsync().finalized((a, b, c) -> profile.getRepository().refreshVersions())
|
||||||
.then(Task.of(Schedulers.javafx(), () -> profile.setSelectedVersion(name)));
|
.then(Task.of(Schedulers.javafx(), () -> profile.setSelectedVersion(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
|
|||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer());
|
transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer());
|
||||||
executor = versionList.refreshAsync(gameVersion, downloadProvider).finalized((variables, isDependentsSucceeded) -> {
|
executor = versionList.refreshAsync(gameVersion, downloadProvider).finalized((variables, isDependentsSucceeded, exception) -> {
|
||||||
if (isDependentsSucceeded) {
|
if (isDependentsSucceeded) {
|
||||||
List<VersionsPageItem> items = loadVersions();
|
List<VersionsPageItem> items = loadVersions();
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
LOG.log(Level.WARNING, "Failed to fetch versions list", (Throwable) variables.get("lastException"));
|
LOG.log(Level.WARNING, "Failed to fetch versions list", exception);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
transitionHandler.setContent(failedPane, ContainerAnimations.FADE.getAnimationProducer());
|
transitionHandler.setContent(failedPane, ContainerAnimations.FADE.getAnimationProducer());
|
||||||
});
|
});
|
||||||
|
@ -92,7 +92,7 @@ public final class ModListPage extends Control {
|
|||||||
modManager.refreshMods();
|
modManager.refreshMods();
|
||||||
return new LinkedList<>(modManager.getMods());
|
return new LinkedList<>(modManager.getMods());
|
||||||
}
|
}
|
||||||
}).finalizedResult(Schedulers.javafx(), (list, isDependentsSucceeded) -> {
|
}).finalizedResult(Schedulers.javafx(), (list, isDependentsSucceeded, exception) -> {
|
||||||
loadingProperty().set(false);
|
loadingProperty().set(false);
|
||||||
if (isDependentsSucceeded)
|
if (isDependentsSucceeded)
|
||||||
FXUtils.onWeakChangeAndOperate(parentTab.getSelectionModel().selectedItemProperty(), newValue -> {
|
FXUtils.onWeakChangeAndOperate(parentTab.getSelectionModel().selectedItemProperty(), newValue -> {
|
||||||
|
@ -52,7 +52,7 @@ public class WorldListPage extends ListPage<WorldListItem> {
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
Task.ofResult(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
Task.ofResult(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
||||||
.finalizedResult(Schedulers.javafx(), (result, isDependentsSucceeded) -> {
|
.finalizedResult(Schedulers.javafx(), (result, isDependentsSucceeded, exception) -> {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (isDependentsSucceeded)
|
if (isDependentsSucceeded)
|
||||||
itemsProperty().setAll(result.stream().map(WorldListItem::new).collect(Collectors.toList()));
|
itemsProperty().setAll(result.stream().map(WorldListItem::new).collect(Collectors.toList()));
|
||||||
|
@ -121,8 +121,7 @@ public final class UpdateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Throwable e = task.getLastException();
|
LOG.log(Level.WARNING, "Failed to update to " + version, executor.getLastException());
|
||||||
LOG.log(Level.WARNING, "Failed to update to " + version, e);
|
|
||||||
Platform.runLater(() -> Controllers.dialog(e.toString(), i18n("update.failed"), MessageBox.ERROR_MESSAGE));
|
Platform.runLater(() -> Controllers.dialog(e.toString(), i18n("update.failed"), MessageBox.ERROR_MESSAGE));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -69,7 +69,7 @@ public class DefaultGameBuilder extends GameBuilder {
|
|||||||
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
|
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}).finalized((variables, isDependentsSucceeded) -> {
|
}).finalized((variables, isDependentsSucceeded, exception) -> {
|
||||||
if (!isDependentsSucceeded)
|
if (!isDependentsSucceeded)
|
||||||
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
||||||
});
|
});
|
||||||
|
@ -20,5 +20,5 @@ package org.jackhuang.hmcl.task;
|
|||||||
import org.jackhuang.hmcl.util.AutoTypingMap;
|
import org.jackhuang.hmcl.util.AutoTypingMap;
|
||||||
|
|
||||||
public interface FinalizedCallback {
|
public interface FinalizedCallback {
|
||||||
void execute(AutoTypingMap<String> variables, boolean isDependentsSucceeded) throws Exception;
|
void execute(AutoTypingMap<String> variables, boolean isDependentsSucceeded, Exception exception) throws Exception;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import java.util.Collections;
|
|||||||
*/
|
*/
|
||||||
final class FinalizedTask extends Task {
|
final class FinalizedTask extends Task {
|
||||||
|
|
||||||
private final Collection<Task> dependents;
|
private final Task pred;
|
||||||
private final FinalizedCallback callback;
|
private final FinalizedCallback callback;
|
||||||
private final Scheduler scheduler;
|
private final Scheduler scheduler;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ final class FinalizedTask extends Task {
|
|||||||
* @param callback a callback that returns the task runs after pred, succ will be executed asynchronously. You can do something that relies on the result of pred.
|
* @param callback a callback that returns the task runs after pred, succ will be executed asynchronously. You can do something that relies on the result of pred.
|
||||||
*/
|
*/
|
||||||
public FinalizedTask(Task pred, Scheduler scheduler, FinalizedCallback callback, String name) {
|
public FinalizedTask(Task pred, Scheduler scheduler, FinalizedCallback callback, String name) {
|
||||||
this.dependents = Collections.singleton(pred);
|
this.pred = pred;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ final class FinalizedTask extends Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
callback.execute(getVariables(), isDependentsSucceeded());
|
callback.execute(getVariables(), isDependentsSucceeded(), pred.getLastException());
|
||||||
|
|
||||||
if (!isDependentsSucceeded())
|
if (!isDependentsSucceeded())
|
||||||
throw new SilentException();
|
throw new SilentException();
|
||||||
@ -61,7 +61,7 @@ final class FinalizedTask extends Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Task> getDependents() {
|
public Collection<Task> getDependents() {
|
||||||
return dependents;
|
return Collections.singleton(pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,13 +68,13 @@ public abstract class Task {
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Throwable lastException = null;
|
private Exception lastException;
|
||||||
|
|
||||||
public Throwable getLastException() {
|
public Exception getLastException() {
|
||||||
return lastException;
|
return lastException;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLastException(Throwable e) {
|
void setLastException(Exception e) {
|
||||||
lastException = e;
|
lastException = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ public abstract class Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<AutoTypingMap<String>, T> success, ExceptionalConsumer<Exception, K> failure) {
|
public final <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<AutoTypingMap<String>, T> success, ExceptionalConsumer<Exception, K> failure) {
|
||||||
return finalized(scheduler, (variables, isDependentsSucceeded) -> {
|
return finalized(scheduler, (variables, isDependentsSucceeded, exception) -> {
|
||||||
if (isDependentsSucceeded) {
|
if (isDependentsSucceeded) {
|
||||||
if (success != null)
|
if (success != null)
|
||||||
try {
|
try {
|
||||||
@ -331,10 +331,9 @@ public abstract class Task {
|
|||||||
if (failure != null)
|
if (failure != null)
|
||||||
failure.accept(e);
|
failure.accept(e);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (failure != null)
|
if (failure != null)
|
||||||
failure.accept(variables.get(TaskExecutor.LAST_EXCEPTION_ID));
|
failure.accept(exception);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,6 @@ public final class TaskExecutor {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
task.setLastException(e);
|
task.setLastException(e);
|
||||||
lastException = e;
|
lastException = e;
|
||||||
variables.set(LAST_EXCEPTION_ID, e);
|
|
||||||
if (task.getSignificance().shouldLog()) {
|
if (task.getSignificance().shouldLog()) {
|
||||||
Logging.LOG.log(Level.FINE, "Task failed: " + task.getName(), e);
|
Logging.LOG.log(Level.FINE, "Task failed: " + task.getName(), e);
|
||||||
}
|
}
|
||||||
@ -279,6 +278,4 @@ public final class TaskExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String LAST_EXCEPTION_ID = "lastException";
|
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public abstract class TaskResult<V> extends Task {
|
|||||||
|
|
||||||
public Task finalizedResult(Scheduler scheduler, FinalizedCallback<V> callback) {
|
public Task finalizedResult(Scheduler scheduler, FinalizedCallback<V> callback) {
|
||||||
return new FinalizedTask(this, scheduler,
|
return new FinalizedTask(this, scheduler,
|
||||||
(variables, isDependentsSucceeded) -> callback.execute(getResult(), isDependentsSucceeded),
|
(variables, isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception),
|
||||||
ReflectionHelper.getCaller().toString());
|
ReflectionHelper.getCaller().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +98,6 @@ public abstract class TaskResult<V> extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface FinalizedCallback<V> {
|
public interface FinalizedCallback<V> {
|
||||||
void execute(V result, boolean isDependentsSucceeded) throws Exception;
|
void execute(V result, boolean isDependentsSucceeded, Exception exception) throws Exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ public interface Validation {
|
|||||||
* Throw an exception when values are malformed.
|
* Throw an exception when values are malformed.
|
||||||
*
|
*
|
||||||
* @throws JsonParseException if fields are filled in wrong format or wrong type.
|
* @throws JsonParseException if fields are filled in wrong format or wrong type.
|
||||||
|
* @throws TolerableValidationException if we want to replace this object with null (i.e. the object does not fulfill the constraints).
|
||||||
*/
|
*/
|
||||||
void validate() throws JsonParseException, TolerableValidationException;
|
void validate() throws JsonParseException, TolerableValidationException;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user