Skip to content

Commit

Permalink
I gave up :/
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenTomato5 committed Nov 3, 2024
1 parent 065160a commit e74539d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/Crash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ jobs:
run: chmod +x gradlew
- name: Build robot code
run: ./gradlew build
- name: Run Simulation
- name: Run Simulation and Capture Logs
env:
CI_NAME: "Crash"
run: ./gradlew simulateJava
run: ./gradlew simulateJava | tee simulateJava.log

- name: Check for Errors in Logs
run: |
if grep -qE "Exception|Error|NULL|NullPointerException" simulateJava.log; then
echo "Errors detected in simulation logs."
exit 1
else
echo "No errors detected in simulation logs."
fi
54 changes: 1 addition & 53 deletions src/main/java/frc/robot/pioneersLib/CI/CrashCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public CrashCheck() {
System.setErr(customErr);

Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
handleError(throwable);
System.exit(1);
});
}

Expand Down Expand Up @@ -190,18 +190,8 @@ public void startCompetition() {
break;
}

checkForErrors();

if (hasErrors()) {
System.out.println("Crashed In " + currentState.get().getStateString());
throw new Error("lallalaal");
// System.exit(1);
// break;
}
// Actually runs periodics
updateState();

// Equivalent to aknowledging disabled/enabled/whatever
if (currentState.get() == CrashCheckStates.DISABLED) {
DriverStationJNI.observeUserProgramDisabled();
} else if (currentState.get() == CrashCheckStates.TELEOP) {
Expand Down Expand Up @@ -230,46 +220,4 @@ public void startCompetition() {
public void endCompetition() {
m_robotMainOverridden = true;
}

private void handleError(Throwable t) {
// Ion even know if this part works fr
hasError.set(true);
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("Error in state ").append(currentState.get().getStateString())
.append(": ").append(t.toString()).append("\n");

// Add stack trace
for (StackTraceElement element : t.getStackTrace()) {
errorMsg.append(" at ").append(element.toString()).append("\n");
}

lastError = errorMsg.toString();
System.err.println(lastError);
}

private boolean hasErrors() {
if (hasError.get()) {
System.err.println("Test failed in state " + currentState.get().getStateString());
System.err.println("Last error:\n" + lastError);
return true;
}
return false;
}

private void checkForErrors() {
String errors = errorStream.toString();
if (errors.contains("Exception") ||
errors.contains("Error") ||
errors.contains("NULL") ||
errors.contains("NullPointerException")) {

hasError.set(true);
lastError = errors;
errorStream.reset(); // Clear the stream for next check

// Print to original error stream for debugging
originalErr.println("Error detected in state " + currentState.get().getStateString());
originalErr.println(lastError);
}
}
}

0 comments on commit e74539d

Please sign in to comment.