Changeset 6797 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2014-02-01T02:15:45+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r6643 r6797 24 24 import org.openstreetmap.josm.actions.ShowStatusReportAction; 25 25 import org.openstreetmap.josm.gui.ExtendedDialog; 26 import org.openstreetmap.josm.gui.preferences.plugin.PluginPreference; 26 27 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 27 28 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 28 29 import org.openstreetmap.josm.gui.widgets.UrlLabel; 30 import org.openstreetmap.josm.plugins.PluginDownloadTask; 29 31 import org.openstreetmap.josm.plugins.PluginHandler; 30 32 … … 37 39 38 40 private static boolean handlingInProgress = false; 41 private static BugReporterThread bugReporterThread = null; 39 42 private static int exceptionCounter = 0; 40 43 private static boolean suppressExceptionDialogs = false; 44 45 private static class BugReporterThread extends Thread { 46 47 final Throwable e; 48 49 public BugReporterThread(Throwable t) { 50 super("Bug Reporter"); 51 this.e = t; 52 } 53 54 @Override 55 public void run() { 56 // Give the user a chance to deactivate the plugin which threw the exception (if it was thrown from a plugin) 57 final PluginDownloadTask pluginDownloadTask = PluginHandler.updateOrdisablePluginAfterException(e); 58 59 SwingUtilities.invokeLater(new Runnable() { 60 @Override 61 public void run() { 62 // Then ask for submitting a bug report, for exceptions thrown from a plugin too, unless updated to a new version 63 if (pluginDownloadTask == null) { 64 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), new String[] {tr("Do nothing"), tr("Report Bug")}); 65 ed.setIcon(JOptionPane.ERROR_MESSAGE); 66 JPanel pnl = new JPanel(new GridBagLayout()); 67 pnl.add(new JLabel( 68 "<html>" + tr("An unexpected exception occurred.<br>" + 69 "This is always a coding error. If you are running the latest<br>" + 70 "version of JOSM, please consider being kind and file a bug report." 71 ) 72 + "</html>"), GBC.eol()); 73 JCheckBox cbSuppress = null; 74 if (exceptionCounter > 1) { 75 cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session.")); 76 pnl.add(cbSuppress, GBC.eol()); 77 } 78 ed.setContent(pnl); 79 ed.showDialog(); 80 if (cbSuppress != null && cbSuppress.isSelected()) { 81 suppressExceptionDialogs = true; 82 } 83 if (ed.getValue() != 2) return; 84 askForBugReport(e); 85 } else { 86 // Ask for restart to install new plugin 87 PluginPreference.notifyDownloadResults(Main.parent, pluginDownloadTask); 88 } 89 } 90 }); 91 } 92 } 41 93 42 94 @Override … … 59 111 */ 60 112 public static void handleException(final Throwable e) { 61 if (handlingInProgress )113 if (handlingInProgress || suppressExceptionDialogs) 62 114 return; // we do not handle secondary exceptions, this gets too messy 63 if ( suppressExceptionDialogs)115 if (bugReporterThread != null && bugReporterThread.isAlive()) 64 116 return; 65 117 handlingInProgress = true; … … 80 132 } 81 133 82 83 SwingUtilities.invokeLater(new Runnable() { 84 @Override 85 public void run() { 86 // Give the user a chance to deactivate the plugin which threw the exception (if it 87 // was thrown from a plugin) 88 // 89 PluginHandler.disablePluginAfterException(e); 90 91 // Then ask for submitting a bug report, for exceptions thrown from a plugin too 92 // 93 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), new String[] {tr("Do nothing"), tr("Report Bug")}); 94 ed.setIcon(JOptionPane.ERROR_MESSAGE); 95 JPanel pnl = new JPanel(new GridBagLayout()); 96 pnl.add(new JLabel( 97 "<html>" 98 + tr("An unexpected exception occurred.<br>" + 99 "This is always a coding error. If you are running the latest<br>" + 100 "version of JOSM, please consider being kind and file a bug report." 101 ) 102 + "</html>"), GBC.eol()); 103 JCheckBox cbSuppress = null; 104 if (exceptionCounter > 1) { 105 cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session.")); 106 pnl.add(cbSuppress, GBC.eol()); 107 } 108 ed.setContent(pnl); 109 ed.showDialog(); 110 if (cbSuppress != null && cbSuppress.isSelected()) { 111 suppressExceptionDialogs = true; 112 } 113 if (ed.getValue() != 2) return; 114 115 try { 116 final int maxlen = 6000; 117 StringWriter stack = new StringWriter(); 118 e.printStackTrace(new PrintWriter(stack)); 119 120 String text = ShowStatusReportAction.getReportHeader() 121 + stack.getBuffer().toString(); 122 String urltext = text.replaceAll("\r",""); /* strip useless return chars */ 123 if(urltext.length() > maxlen) 124 { 125 urltext = urltext.substring(0,maxlen); 126 int idx = urltext.lastIndexOf('\n'); 127 /* cut whole line when not loosing too much */ 128 if(maxlen-idx < 200) { 129 urltext = urltext.substring(0,idx+1); 130 } 131 urltext += "...<snip>...\n"; 132 } 133 134 JPanel p = new JPanel(new GridBagLayout()); 135 p.add(new JMultilineLabel( 136 tr("You have encountered an error in JOSM. Before you file a bug report " + 137 "make sure you have updated to the latest version of JOSM here:")), GBC.eol()); 138 p.add(new UrlLabel(Main.JOSM_WEBSITE,2), GBC.eop().insets(8,0,0,0)); 139 p.add(new JMultilineLabel( 140 tr("You should also update your plugins. If neither of those help please " + 141 "file a bug report in our bugtracker using this link:")), GBC.eol()); 142 p.add(getBugReportUrlLabel(urltext), GBC.eop().insets(8,0,0,0)); 143 p.add(new JMultilineLabel( 144 tr("There the error information provided below should already be " + 145 "filled in for you. Please include information on how to reproduce " + 146 "the error and try to supply as much detail as possible.")), GBC.eop()); 147 p.add(new JMultilineLabel( 148 tr("Alternatively, if that does not work you can manually fill in the information " + 149 "below at this URL:")), GBC.eol()); 150 p.add(new UrlLabel(Main.JOSM_WEBSITE+"/newticket",2), GBC.eop().insets(8,0,0,0)); 151 if (Utils.copyToClipboard(text)) { 152 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 153 } 154 155 JosmTextArea info = new JosmTextArea(text, 18, 60); 156 info.setCaretPosition(0); 157 info.setEditable(false); 158 p.add(new JScrollPane(info), GBC.eop()); 159 160 for (Component c: p.getComponents()) { 161 if (c instanceof JMultilineLabel) { 162 ((JMultilineLabel)c).setMaxWidth(400); 163 } 164 } 165 166 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE); 167 } catch (Exception e1) { 168 Main.error(e1); 169 } 170 } 171 }); 134 bugReporterThread = new BugReporterThread(e); 135 bugReporterThread.start(); 172 136 } 173 137 } finally { 174 138 handlingInProgress = false; 139 } 140 } 141 142 private static void askForBugReport(final Throwable e) { 143 try { 144 final int maxlen = 6000; 145 StringWriter stack = new StringWriter(); 146 e.printStackTrace(new PrintWriter(stack)); 147 148 String text = ShowStatusReportAction.getReportHeader() + stack.getBuffer().toString(); 149 String urltext = text.replaceAll("\r",""); 150 if (urltext.length() > maxlen) { 151 urltext = urltext.substring(0,maxlen); 152 int idx = urltext.lastIndexOf('\n'); 153 // cut whole line when not loosing too much 154 if (maxlen-idx < 200) { 155 urltext = urltext.substring(0,idx+1); 156 } 157 urltext += "...<snip>...\n"; 158 } 159 160 JPanel p = new JPanel(new GridBagLayout()); 161 p.add(new JMultilineLabel( 162 tr("You have encountered an error in JOSM. Before you file a bug report " + 163 "make sure you have updated to the latest version of JOSM here:")), GBC.eol()); 164 p.add(new UrlLabel(Main.JOSM_WEBSITE,2), GBC.eop().insets(8,0,0,0)); 165 p.add(new JMultilineLabel( 166 tr("You should also update your plugins. If neither of those help please " + 167 "file a bug report in our bugtracker using this link:")), GBC.eol()); 168 p.add(getBugReportUrlLabel(urltext), GBC.eop().insets(8,0,0,0)); 169 p.add(new JMultilineLabel( 170 tr("There the error information provided below should already be " + 171 "filled in for you. Please include information on how to reproduce " + 172 "the error and try to supply as much detail as possible.")), GBC.eop()); 173 p.add(new JMultilineLabel( 174 tr("Alternatively, if that does not work you can manually fill in the information " + 175 "below at this URL:")), GBC.eol()); 176 p.add(new UrlLabel(Main.JOSM_WEBSITE+"/newticket",2), GBC.eop().insets(8,0,0,0)); 177 if (Utils.copyToClipboard(text)) { 178 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 179 } 180 181 JosmTextArea info = new JosmTextArea(text, 18, 60); 182 info.setCaretPosition(0); 183 info.setEditable(false); 184 p.add(new JScrollPane(info), GBC.eop()); 185 186 for (Component c: p.getComponents()) { 187 if (c instanceof JMultilineLabel) { 188 ((JMultilineLabel)c).setMaxWidth(400); 189 } 190 } 191 192 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE); 193 } catch (Exception e1) { 194 Main.error(e1); 175 195 } 176 196 }
Note: See TracChangeset
for help on using the changeset viewer.