1 package com.neuronrobotics.bowlerstudio;
3 import java.io.IOException;
4 import java.lang.Thread.UncaughtExceptionHandler;
5 import java.util.ArrayList;
6 import java.util.HashMap;
8 import java.util.Optional;
10 import org.kohsuke.github.GHIssue;
11 import org.kohsuke.github.GHIssueBuilder;
12 import org.kohsuke.github.GHIssueComment;
13 import org.kohsuke.github.GHIssueState;
14 import org.kohsuke.github.GHRepository;
15 import org.kohsuke.github.GHUser;
16 import org.kohsuke.github.GitHub;
18 import com.neuronrobotics.bowlerkernel.BowlerKernelBuildInfo;
19 import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
20 import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
21 import com.neuronrobotics.javacad.JavaCadBuildInfo;
22 import com.neuronrobotics.sdk.config.SDKBuildInfo;
23 import com.neuronrobotics.video.OSUtil;
25 import javafx.application.Platform;
26 import javafx.scene.control.Alert;
27 import javafx.scene.control.Alert.AlertType;
28 import javafx.scene.control.ButtonType;
32 String stacktraceFromHandlerInstantiation;
35 private static HashMap<Throwable, String>
exceptionQueue =
new HashMap<Throwable, String>();
38 private static HashMap<String, Integer>
exceptionCounter =
new HashMap<String, Integer>();
41 stacktraceFromHandlerInstantiation = org.apache.commons.lang.exception.ExceptionUtils
42 .getStackTrace(
new Exception());
48 except(
new Exception(
"A null exception was thrown"));
56 runLater(r,
new Exception(
"UI Thread Exception here!"));
59 public static void runLater(Runnable r, Throwable ex) {
60 Platform.runLater(() -> {
63 }
catch (Throwable t) {
71 public void except(Throwable e, String stacktraceFromCatch) {
72 System.out.println(stacktraceFromCatch);
74 String stacktrace = org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e);
75 StackTraceElement[] element = e.getStackTrace();
92 if (element.length > 0) {
93 if (element[0].getClassName() !=
null)
94 if (element[0].getClassName().contains(
"com.sun.scenario.animation.AbstractMasterTimer")) {
98 }
catch (InterruptedException e1) {
100 e1.printStackTrace();
105 }
else if (element[0].getClassName().contains(
"javafx.embed.swing.SwingNode")) {
109 }
catch (InterruptedException e1) {
111 e1.printStackTrace();
119 }
else if (java.lang.OutOfMemoryError.class.isInstance(e)
120 || stacktrace.contains(
"java.lang.OutOfMemoryError")) {
126 String javaVersion = System.getProperty(
"java.version");
127 String javafxVersion = System.getProperty(
"javafx.version");
131 +
"Java Version: " + javaVersion +
"\n" +
"JavaFX Version: " + javafxVersion +
"\n" +
"\nOS = "
132 + OSUtil.getOsName() +
" " + OSUtil.getOsArch() +
" " + (OSUtil.is64Bit() ?
"x64" :
"x86") +
"\r\n"
133 +
"```\n" + stacktrace +
"\n```" +
"\n\nCaught and reported at: \n" +
"```\n" + stacktraceFromCatch
134 +
"\n```\n" +
"\nIssueReportingExceptionHandler Created at:\n" +
"\n```\n"
135 + stacktraceFromHandlerInstantiation +
"\n```\n";
136 System.err.println(body);
137 System.err.println(
"\r\n\r\nBug Reported!\r\n\r\n");
138 System.out.println(body);
139 System.out.println(
"\r\n\r\nBug Reported!\r\n\r\n");
142 if (github ==
null || github.isAnonymous())
149 Platform.runLater(() -> {
150 Alert alert =
new Alert(AlertType.CONFIRMATION);
151 alert.setTitle(
"An Error occoured");
152 alert.setHeaderText(
"Would it be ok if I report this issue back to Kevin so he can fix it?");
153 alert.setContentText(
"Are you ok with this?");
154 Optional<ButtonType> result = alert.showAndWait();
155 if (result.get() == ButtonType.OK) {
166 private void runReport(StackTraceElement[] element, String body, GitHub github) {
169 GHRepository repo = github.getOrganization(
"CommonWealthRobotics").getRepository(
"BowlerStudio");
170 List<GHIssue> issues = repo.getIssues(GHIssueState.ALL);
173 for (GHIssue i : issues) {
174 System.err.println(
"Issues are :" + i.getTitle());
175 if (i.getTitle().contains(source)) {
176 List<GHIssueComment> comments = i.getComments();
178 boolean metoo = false;
181 GHUser user = i.getUser();
183 String name = user.getName();
185 String username = PasswordManager.getUsername();
186 if (username != null) {
187 metoo = name.contentEquals(username);
188 for (GHIssueComment comment : comments) {
190 if (comment.getUser().getName().contentEquals(username)) {
197 } catch (Throwable t) {
203 if (i.getState() == GHIssueState.CLOSED) {
206 } catch (Throwable t) {
216 .label(
"BUG").label(
"AUTO_REPORTED").assignee(
"madhephaestus").create();
219 }
catch (Throwable e) {
225 Throwable exception = (Throwable) exceptionQueue.keySet().toArray()[0];
226 String source = exceptionQueue.remove(exception);
227 except(exception, source);
234 String stacktraceFromCatch = org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(
new Exception());
235 StackTraceElement[] element = t.getStackTrace();
237 String className = element[0].getClassName();
238 if (checkIgnoreExceptions(t)) {
242 if (Platform.isFxApplicationThread()) {
244 System.err.println(
"Exception in Javafx thread! \n"
245 + org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(t));
247 if (fxExceptionCount > 10) {
248 System.err.println(stacktraceFromCatch);
252 throw new RuntimeException(t);
256 exceptionQueue.put(t, stacktraceFromCatch);
260 except(t, stacktraceFromCatch);
265 return t.getStackTrace()[0].getClassName().contains(
"DropHandler") || t.getMessage().contains(
"Key already associated with a running event loop");
266 }
catch(Throwable tf) {
272 return getTitle(element.getStackTrace());
275 public static String
getTitle(StackTraceElement[] element) {
276 if (element.length == 0)
277 return "No exception trace found";
278 return element[0].getClassName() +
" at line " + element[0].getLineNumber();
static String getVersion()
static void upenURL(String string)
static HashMap< String, Integer > exceptionCounter
static int timerErrorCount
void except(Throwable e, String stacktraceFromCatch)
static HashMap< Throwable, String > exceptionQueue
void uncaughtException(Thread t, Throwable e)
static void runLater(Runnable r)
static void runLater(Runnable r, Throwable ex)
IssueReportingExceptionHandler()
static boolean reportIssues
boolean checkIgnoreExceptions(Throwable t)
static String getTitle(StackTraceElement[] element)
static boolean processing
static String getTitle(Throwable element)
void runReport(StackTraceElement[] element, String body, GitHub github)
static String getVersion()
static GitHub getGithub()
static String getVersion()
static String getVersion()