Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-722 - updated error dialog to handle unchecked error text

dragonmacherbd98beb1f280
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DockingErrorDisplay.java b/Ghidra/Framework/Docking/src/main/java/docking/DockingErrorDisplay.java
index 5647b31906..3fd195d9cc 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/DockingErrorDisplay.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/DockingErrorDisplay.java
@@ -18,6 +18,8 @@ package docking;
import java.awt.Component;
import java.awt.Window;
+import org.apache.commons.text.WordUtils;
+
import docking.widgets.OkDialog;
import docking.widgets.OptionDialog;
import ghidra.util.*;
@@ -26,11 +28,11 @@ import ghidra.util.exception.MultipleCauses;
public class DockingErrorDisplay implements ErrorDisplay {
/**
- * Error dialog used to append exceptions.
- *
+ * Error dialog used to append exceptions.
+ *
* <p>While this dialog is showing all new exceptions will be added to the dialog. When
- * this dialog is closed, this reference will be cleared.
- *
+ * this dialog is closed, this reference will be cleared.
+ *
* <p>Note: all use of this variable <b>must be on the Swing thread</b> to avoid thread
* visibility issues.
*/
@@ -62,23 +64,34 @@ public class DockingErrorDisplay implements ErrorDisplay {
Component parent, String title, Object message, Throwable throwable) {
int dialogType = OptionDialog.PLAIN_MESSAGE;
+
String messageString = message != null ? message.toString() : null;
- String rawMessage = HTMLUtilities.fromHTML(messageString);
+ if (messageString != null) {
+ // prevent excessive message degenerate cases
+ int maxChars = 1000;
+ String safeMessage = StringUtilities.trimMiddle(messageString, maxChars);
+
+ // wrap any poorly formatted text that gets displayed in the label; 80-100 chars is
+ // a reasonable line length based on historical print margins
+ messageString = WordUtils.wrap(safeMessage, 100, null, true);
+ }
+
+ String unformattedMessage = HTMLUtilities.fromHTML(messageString);
switch (messageType) {
case INFO:
dialogType = OptionDialog.INFORMATION_MESSAGE;
consoleDisplay.displayInfoMessage(errorLogger, originator, parent, title,
- rawMessage);
+ unformattedMessage);
break;
case WARNING:
case ALERT:
dialogType = OptionDialog.WARNING_MESSAGE;
consoleDisplay.displayWarningMessage(errorLogger, originator, parent, title,
- rawMessage, throwable);
+ unformattedMessage, throwable);
break;
case ERROR:
consoleDisplay.displayErrorMessage(errorLogger, originator, parent, title,
- rawMessage, throwable);
+ unformattedMessage, throwable);
dialogType = OptionDialog.ERROR_MESSAGE;
break;
}
@@ -93,8 +106,8 @@ public class DockingErrorDisplay implements ErrorDisplay {
return component;
}
- private void showDialog(final String title, final Throwable throwable,
- final int dialogType, final String messageString, final Component parent) {
+ private void showDialog(final String title, final Throwable throwable, final int dialogType,
+ final String messageString, final Component parent) {
Swing.runIfSwingOrRunLater(() -> {
@@ -108,8 +121,8 @@ public class DockingErrorDisplay implements ErrorDisplay {
});
}
- private void showDialogOnSwing(String title, Throwable throwable,
- int dialogType, String messageString, Component parent) {
+ private void showDialogOnSwing(String title, Throwable throwable, int dialogType,
+ String messageString, Component parent) {
if (activeDialog != null) {
activeDialog.addException(messageString, throwable);
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/ErrLogDialog.java b/Ghidra/Framework/Docking/src/main/java/docking/ErrLogDialog.java
index 0f02fc7c40..3eaf3c950d 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/ErrLogDialog.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/ErrLogDialog.java
@@ -43,7 +43,7 @@ import ghidra.util.table.column.GColumnRenderer;
import utilities.util.reflection.ReflectionUtilities;
/**
- * A dialog that takes error text and displays it with an option details button. If there is
+ * A dialog that takes error text and displays it with an option details button. If there is
* an {@link ErrorReporter}, then a button is provided to report the error.
*/
public class ErrLogDialog extends AbstractErrDialog {
@@ -149,7 +149,8 @@ public class ErrLogDialog extends AbstractErrDialog {
introPanel.add(
new GIconLabel(UIManager.getIcon("OptionPane.errorIcon"), SwingConstants.RIGHT),
BorderLayout.WEST);
- introPanel.add(new GHtmlLabel(HTMLUtilities.toHTML(message)) {
+ String html = HTMLUtilities.toHTML(message);
+ introPanel.add(new GHtmlLabel(html) {
@Override
public Dimension getPreferredSize() {
// rendering HTML the label can expand larger than the screen; keep it reasonable
@@ -387,6 +388,16 @@ public class ErrLogDialog extends AbstractErrDialog {
textDetails.scrollToBottom();
}
+ @Override
+ public Dimension getPreferredSize() {
+ Dimension size = super.getPreferredSize();
+
+ // Cap preferred width to something reasonable; most displays have more than 1000 width.
+ // Users can still resize as desired
+ size.width = Math.min(size.width, 1000);
+ return size;
+ }
+
void setError(ErrorEntry e) {
error = e;
setExceptionMessage(e.getDetailsText());