remove lastException in task.variables
This commit is contained in:
@@ -69,7 +69,7 @@ public class DefaultGameBuilder extends GameBuilder {
|
||||
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
|
||||
|
||||
return result;
|
||||
}).finalized((variables, isDependentsSucceeded) -> {
|
||||
}).finalized((variables, isDependentsSucceeded, exception) -> {
|
||||
if (!isDependentsSucceeded)
|
||||
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
||||
});
|
||||
|
||||
@@ -20,5 +20,5 @@ package org.jackhuang.hmcl.task;
|
||||
import org.jackhuang.hmcl.util.AutoTypingMap;
|
||||
|
||||
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 {
|
||||
|
||||
private final Collection<Task> dependents;
|
||||
private final Task pred;
|
||||
private final FinalizedCallback callback;
|
||||
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.
|
||||
*/
|
||||
public FinalizedTask(Task pred, Scheduler scheduler, FinalizedCallback callback, String name) {
|
||||
this.dependents = Collections.singleton(pred);
|
||||
this.pred = pred;
|
||||
this.scheduler = scheduler;
|
||||
this.callback = callback;
|
||||
|
||||
@@ -53,7 +53,7 @@ final class FinalizedTask extends Task {
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
callback.execute(getVariables(), isDependentsSucceeded());
|
||||
callback.execute(getVariables(), isDependentsSucceeded(), pred.getLastException());
|
||||
|
||||
if (!isDependentsSucceeded())
|
||||
throw new SilentException();
|
||||
@@ -61,7 +61,7 @@ final class FinalizedTask extends Task {
|
||||
|
||||
@Override
|
||||
public Collection<Task> getDependents() {
|
||||
return dependents;
|
||||
return Collections.singleton(pred);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,13 +68,13 @@ public abstract class Task {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
private Throwable lastException = null;
|
||||
private Exception lastException;
|
||||
|
||||
public Throwable getLastException() {
|
||||
public Exception getLastException() {
|
||||
return lastException;
|
||||
}
|
||||
|
||||
void setLastException(Throwable e) {
|
||||
void setLastException(Exception 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) {
|
||||
return finalized(scheduler, (variables, isDependentsSucceeded) -> {
|
||||
return finalized(scheduler, (variables, isDependentsSucceeded, exception) -> {
|
||||
if (isDependentsSucceeded) {
|
||||
if (success != null)
|
||||
try {
|
||||
@@ -331,10 +331,9 @@ public abstract class Task {
|
||||
if (failure != null)
|
||||
failure.accept(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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) {
|
||||
task.setLastException(e);
|
||||
lastException = e;
|
||||
variables.set(LAST_EXCEPTION_ID, e);
|
||||
if (task.getSignificance().shouldLog()) {
|
||||
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) {
|
||||
return new FinalizedTask(this, scheduler,
|
||||
(variables, isDependentsSucceeded) -> callback.execute(getResult(), isDependentsSucceeded),
|
||||
(variables, isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception),
|
||||
ReflectionHelper.getCaller().toString());
|
||||
}
|
||||
|
||||
@@ -98,6 +98,6 @@ public abstract class TaskResult<V> extends Task {
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user