Skip to content

Commit 00cfb86

Browse files
committed
[wpilibj] Fix incorrect robot name in reported error
1 parent 35dd61c commit 00cfb86

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,15 @@ private static <T extends RobotBase> void runRobot(Supplier<T> robotSupplier) {
382382
}
383383
String robotName = "Unknown";
384384
StackTraceElement[] elements = throwable.getStackTrace();
385-
if (elements.length > 0) {
386-
robotName = elements[0].getClassName();
385+
for (var element : elements) {
386+
try {
387+
if (RobotBase.class.isAssignableFrom(Class.forName(element.getClassName()))) {
388+
robotName = element.getClassName();
389+
break;
390+
}
391+
} catch (ClassNotFoundException e) {
392+
// The class is in the stack trace, it better exist
393+
}
387394
}
388395
DriverStation.reportError(
389396
"Unhandled exception instantiating robot " + robotName + " " + throwable, elements);

0 commit comments

Comments
 (0)