Display more friendly error message when fail to install library

This commit is contained in:
huanghongxun
2019-02-17 13:45:10 +08:00
parent e3d2a4bf9d
commit 9062c2e447
8 changed files with 26 additions and 29 deletions

View File

@@ -20,6 +20,7 @@ package org.jackhuang.hmcl.download.game;
import org.jackhuang.hmcl.download.AbstractDependencyManager;
import org.jackhuang.hmcl.download.DefaultCacheRepository;
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.task.DownloadException;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.FileDownloadTask.IntegrityCheck;
import org.jackhuang.hmcl.task.Task;
@@ -88,10 +89,10 @@ public class LibraryDownloadTask extends Task {
if (cached) return;
if (!isDependentsSucceeded()) {
// Since FileDownloadTask wraps the actual exception with another IOException.
// Since FileDownloadTask wraps the actual exception with DownloadException.
// We should extract it letting the error message clearer.
Throwable t = task.getLastException();
if (t.getCause() != null)
if (t instanceof DownloadException)
throw new LibraryDownloadException(library, t.getCause());
else
throw new LibraryDownloadException(library, t);

View File

@@ -20,12 +20,14 @@ package org.jackhuang.hmcl.task;
import java.io.IOException;
import java.net.URL;
import static java.util.Objects.requireNonNull;
public class DownloadException extends IOException {
private final URL url;
public DownloadException(URL url, Throwable cause) {
super("Unable to download " + url + ", " + cause.getMessage(), cause);
super("Unable to download " + url + ", " + cause.getMessage(), requireNonNull(cause));
this.url = url;
}