forked from External/mage
GUI: reworked error dialog:
* added client version and improved stack trace; * added copy to clipboard button; * added button to create new issue on github (with prefilled form fields like error text); * added GUI size settings support; * some old errors now use new error dialog instead message box;
This commit is contained in:
parent
2631b31b8a
commit
6c0f7ebb90
11 changed files with 284 additions and 125 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package mage.client;
|
||||
|
||||
import mage.MageException;
|
||||
import mage.cards.RateCard;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardRepository;
|
||||
|
|
@ -38,7 +39,6 @@ import mage.client.util.stats.UpdateMemUsageTask;
|
|||
import mage.components.ImagePanel;
|
||||
import mage.components.ImagePanelStyle;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.cards.RateCard;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
|
|
@ -72,14 +72,13 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.SocketException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.prefs.Preferences;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Client app
|
||||
|
|
@ -1356,11 +1355,52 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
userRequestDialog.showDialog(userRequestMessage);
|
||||
}
|
||||
|
||||
public void showErrorDialog(final String title, final String message) {
|
||||
public void showErrorDialog(String errorType, Exception e) {
|
||||
String errorMessage = e.getMessage();
|
||||
if (errorMessage == null || errorMessage.isEmpty() || errorMessage.equals("Null")) {
|
||||
errorMessage = e.getClass().getSimpleName() + " - look at server or client logs for more details";
|
||||
}
|
||||
|
||||
int maxLines = 10;
|
||||
String newLine = "\n";
|
||||
|
||||
// main error
|
||||
String mainError = Arrays.stream(e.getStackTrace())
|
||||
.map(StackTraceElement::toString)
|
||||
.limit(maxLines)
|
||||
.collect(Collectors.joining(newLine));
|
||||
if (e.getStackTrace().length > maxLines) {
|
||||
mainError += newLine + "and other " + (e.getStackTrace().length - maxLines) + " lines";
|
||||
}
|
||||
|
||||
// root error
|
||||
String rootError = "";
|
||||
Throwable root = ThreadUtils.findRootException(e);
|
||||
if (root != e) {
|
||||
rootError = Arrays.stream(root.getStackTrace())
|
||||
.map(StackTraceElement::toString)
|
||||
.limit(maxLines)
|
||||
.collect(Collectors.joining(newLine));
|
||||
if (root.getStackTrace().length > maxLines) {
|
||||
rootError += newLine + "and other " + (root.getStackTrace().length - maxLines) + " lines";
|
||||
}
|
||||
}
|
||||
|
||||
String allErrors = mainError;
|
||||
if (!rootError.isEmpty()) {
|
||||
allErrors += newLine + "Root caused by:" + newLine + rootError;
|
||||
}
|
||||
showErrorDialog(errorType,
|
||||
e.getClass().getSimpleName(),
|
||||
errorMessage + newLine + newLine + "Stack trace:" + newLine + allErrors
|
||||
);
|
||||
}
|
||||
|
||||
public void showErrorDialog(String errorType, String errorTitle, String errorText) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
errorDialog.showDialog(title, message);
|
||||
errorDialog.showDialog(errorType, errorTitle, errorText);
|
||||
} else {
|
||||
SwingUtilities.invokeLater(() -> errorDialog.showDialog(title, message));
|
||||
SwingUtilities.invokeLater(() -> errorDialog.showDialog(errorType, errorTitle, errorText));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1587,7 +1627,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
.filter(Component::isVisible)
|
||||
.filter(p -> p instanceof MagePane)
|
||||
.map(p -> (MagePane) p)
|
||||
.filter(p-> !onlyActive || p.isActiveTable())
|
||||
.filter(p -> !onlyActive || p.isActiveTable())
|
||||
.count();
|
||||
}
|
||||
|
||||
|
|
@ -1813,21 +1853,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
|
||||
this.connectDialog.changeGUISize();
|
||||
this.errorDialog.changeGUISize();
|
||||
|
||||
updateTooltipContainerSizes();
|
||||
}
|
||||
|
||||
public static void showWhatsNewDialog() {
|
||||
try {
|
||||
URI newsURI = new URI("https://jaydi85.github.io/xmage-web-news/news.html");
|
||||
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
|
||||
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
|
||||
desktop.browse(newsURI);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.error("URI Syntax error when creating news link", e);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IOException while loading news page", e);
|
||||
}
|
||||
AppUtil.openUrlInBrowser("https://jaydi85.github.io/xmage-web-news/news.html");
|
||||
}
|
||||
|
||||
public boolean isGameFrameActive(UUID gameId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue