- Timestamp:
- 2011-12-29T15:45:55+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r4607 r4743 17 17 import javax.swing.JScrollPane; 18 18 import javax.swing.JTextArea; 19 import javax.swing.SwingUtilities; 19 20 20 21 import org.openstreetmap.josm.Main; 21 22 import org.openstreetmap.josm.actions.ShowStatusReportAction; 23 import org.openstreetmap.josm.gui.ExtendedDialog; 22 24 import org.openstreetmap.josm.gui.JMultilineLabel; 23 25 import org.openstreetmap.josm.plugins.PluginHandler; 24 25 import javax.swing.JPanel;26 import org.openstreetmap.josm.gui.ExtendedDialog;27 import org.openstreetmap.josm.tools.GBC;28 import java.awt.GridBagLayout;29 26 30 27 /** … … 48 45 } 49 46 50 public static void handleException(Throwable e) { 47 public static void handleException(final Throwable e) { 51 48 if (handlingInProgress) 52 49 return; // we do not handle secondary exceptions, this gets too messy … … 66 63 "Error", 67 64 JOptionPane.ERROR_MESSAGE 68 ); 65 ); 69 66 return; 70 67 } 71 68 72 // Give the user a chance to deactivate the plugin which threw the exception (if it73 // was thrown from a plugin)74 //75 PluginHandler.disablePluginAfterException(e);76 69 77 // Then ask for submitting a bug report, for exceptions thrown from a plugin too 78 // 79 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), new String[] {tr("Do nothing"), tr("Report Bug")}); 80 ed.setIcon(JOptionPane.ERROR_MESSAGE); 81 JPanel pnl = new JPanel(new GridBagLayout()); 82 pnl.add(new JLabel( 83 "<html>" 84 + tr("An unexpected exception occurred.<br>" + 85 "This is always a coding error. If you are running the latest<br>" + 86 "version of JOSM, please consider being kind and file a bug report." 87 ) 88 + "</html>"), GBC.eol()); 89 JCheckBox cbSuppress = null; 90 if (exceptionCounter > 1) { 91 cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session.")); 92 pnl.add(cbSuppress, GBC.eol()); 93 } 94 ed.setContent(pnl); 95 ed.showDialog(); 96 if (cbSuppress != null && cbSuppress.isSelected()) { 97 suppressExceptionDialogs = true; 98 } 99 if (ed.getValue() != 2) return; 100 101 try { 102 final int maxlen = 6000; 103 StringWriter stack = new StringWriter(); 104 e.printStackTrace(new PrintWriter(stack)); 70 SwingUtilities.invokeLater(new Runnable() { 71 @Override 72 public void run() { 73 // Give the user a chance to deactivate the plugin which threw the exception (if it 74 // was thrown from a plugin) 75 // 76 PluginHandler.disablePluginAfterException(e); 105 77 106 String text = ShowStatusReportAction.getReportHeader() 107 + stack.getBuffer().toString(); 108 String urltext = text.replaceAll("\r",""); /* strip useless return chars */ 109 if(urltext.length() > maxlen) 110 { 111 urltext = urltext.substring(0,maxlen); 112 int idx = urltext.lastIndexOf("\n"); 113 /* cut whole line when not loosing too much */ 114 if(maxlen-idx < 200) { 115 urltext = urltext.substring(0,idx+1); 78 // Then ask for submitting a bug report, for exceptions thrown from a plugin too 79 // 80 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), new String[] {tr("Do nothing"), tr("Report Bug")}); 81 ed.setIcon(JOptionPane.ERROR_MESSAGE); 82 JPanel pnl = new JPanel(new GridBagLayout()); 83 pnl.add(new JLabel( 84 "<html>" 85 + tr("An unexpected exception occurred.<br>" + 86 "This is always a coding error. If you are running the latest<br>" + 87 "version of JOSM, please consider being kind and file a bug report." 88 ) 89 + "</html>"), GBC.eol()); 90 JCheckBox cbSuppress = null; 91 if (exceptionCounter > 1) { 92 cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session.")); 93 pnl.add(cbSuppress, GBC.eol()); 116 94 } 117 urltext += "...<snip>...\n"; 118 } 95 ed.setContent(pnl); 96 ed.showDialog(); 97 if (cbSuppress != null && cbSuppress.isSelected()) { 98 suppressExceptionDialogs = true; 99 } 100 if (ed.getValue() != 2) return; 119 101 120 URL url = new URL("http://josm.openstreetmap.de/josmticket?" + 121 "tdata="+Base64.encode(ByteBuffer.wrap(urltext.getBytes("UTF8")), true)); 102 try { 103 final int maxlen = 6000; 104 StringWriter stack = new StringWriter(); 105 e.printStackTrace(new PrintWriter(stack)); 122 106 123 JPanel p = new JPanel(new GridBagLayout()); 124 p.add(new JMultilineLabel( 125 tr("You have encountered an error in JOSM. Before you file a bug report " + 126 "make sure you have updated to the latest version of JOSM here:")), GBC.eol()); 127 p.add(new UrlLabel("http://josm.openstreetmap.de/#Download"), GBC.eop().insets(8,0,0,0)); 128 p.add(new JMultilineLabel( 129 tr("You should also update your plugins. If neither of those help please " + 130 "file a bug report in our bugtracker using this link:")), GBC.eol()); 131 p.add(new UrlLabel(url.toString(), "http://josm.openstreetmap.de/josmticket?..."), GBC.eop().insets(8,0,0,0)); 132 p.add(new JMultilineLabel( 133 tr("There the error information provided below should already be " + 134 "filled in for you. Please include information on how to reproduce " + 135 "the error and try to supply as much detail as possible.")), GBC.eop()); 136 p.add(new JMultilineLabel( 137 tr("Alternatively, if that does not work you can manually fill in the information " + 138 "below at this URL:")), GBC.eol()); 139 p.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eop().insets(8,0,0,0)); 140 if (Utils.copyToClipboard(text)) { 141 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 142 } 107 String text = ShowStatusReportAction.getReportHeader() 108 + stack.getBuffer().toString(); 109 String urltext = text.replaceAll("\r",""); /* strip useless return chars */ 110 if(urltext.length() > maxlen) 111 { 112 urltext = urltext.substring(0,maxlen); 113 int idx = urltext.lastIndexOf("\n"); 114 /* cut whole line when not loosing too much */ 115 if(maxlen-idx < 200) { 116 urltext = urltext.substring(0,idx+1); 117 } 118 urltext += "...<snip>...\n"; 119 } 143 120 144 JTextArea info = new JTextArea(text, 20, 60); 145 info.setCaretPosition(0); 146 info.setEditable(false); 147 p.add(new JScrollPane(info), GBC.eop()); 121 URL url = new URL("http://josm.openstreetmap.de/josmticket?" + 122 "tdata="+Base64.encode(ByteBuffer.wrap(urltext.getBytes("UTF8")), true)); 148 123 149 for (Component c: p.getComponents()) { 150 if (c instanceof JMultilineLabel) { 151 ((JMultilineLabel)c).setMaxWidth(400); 124 JPanel p = new JPanel(new GridBagLayout()); 125 p.add(new JMultilineLabel( 126 tr("You have encountered an error in JOSM. Before you file a bug report " + 127 "make sure you have updated to the latest version of JOSM here:")), GBC.eol()); 128 p.add(new UrlLabel("http://josm.openstreetmap.de/#Download"), GBC.eop().insets(8,0,0,0)); 129 p.add(new JMultilineLabel( 130 tr("You should also update your plugins. If neither of those help please " + 131 "file a bug report in our bugtracker using this link:")), GBC.eol()); 132 p.add(new UrlLabel(url.toString(), "http://josm.openstreetmap.de/josmticket?..."), GBC.eop().insets(8,0,0,0)); 133 p.add(new JMultilineLabel( 134 tr("There the error information provided below should already be " + 135 "filled in for you. Please include information on how to reproduce " + 136 "the error and try to supply as much detail as possible.")), GBC.eop()); 137 p.add(new JMultilineLabel( 138 tr("Alternatively, if that does not work you can manually fill in the information " + 139 "below at this URL:")), GBC.eol()); 140 p.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eop().insets(8,0,0,0)); 141 if (Utils.copyToClipboard(text)) { 142 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 143 } 144 145 JTextArea info = new JTextArea(text, 20, 60); 146 info.setCaretPosition(0); 147 info.setEditable(false); 148 p.add(new JScrollPane(info), GBC.eop()); 149 150 for (Component c: p.getComponents()) { 151 if (c instanceof JMultilineLabel) { 152 ((JMultilineLabel)c).setMaxWidth(400); 153 } 154 } 155 156 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE); 157 } catch (Exception e1) { 158 e1.printStackTrace(); 152 159 } 153 160 } 154 155 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE); 156 } catch (Exception e1) { 157 e1.printStackTrace(); 158 } 161 }); 159 162 } 160 163 } finally {
Note:
See TracChangeset
for help on using the changeset viewer.