-
Notifications
You must be signed in to change notification settings - Fork 9
fix(reporter): fix PasteBin upload (missing Jackson dep) and always log upload failures #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,11 @@ public URL getUploadedFileURL() { | |
| return uploadURL; | ||
| } | ||
|
|
||
| /** Package-private test hook - equivalent to a real "PasteBin" click, but with a caller-supplied Callable. */ | ||
| void uploadForTesting(Callable<URL> callable) { | ||
| upload(callable); | ||
| } | ||
|
Comment on lines
+122
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test-exclusive methods should not exist within a class. There should be some other means of testing this, perhaps through UI automation? |
||
|
|
||
| private void upload(final Callable<URL> callable) { | ||
| Runnable runnable = new Runnable() { | ||
|
|
||
|
|
@@ -169,6 +174,14 @@ public void run() { | |
| } | ||
|
|
||
| private void uploadFailed(final Exception e) { | ||
| // Printed unconditionally, not just shown in the dialog below: a JOptionPane only reaches | ||
| // whoever is watching the screen at that exact moment, and leaves no trace at all once | ||
| // it's dismissed - nothing else in this codebase logs upload failures anywhere. Whoever | ||
| // launched this process (a script, a supervisor, a developer tailing output) needs to be | ||
| // able to find out what happened after the fact, not just the person who happened to be | ||
| // looking right then. | ||
| e.printStackTrace(System.err); | ||
|
|
||
| SwingUtilities.invokeLater(new Runnable() { | ||
|
|
||
| @Override | ||
|
|
||
65 changes: 65 additions & 0 deletions
65
cr-core/src/test/java/org/terasology/crashreporter/pages/UploadPanelFailureLoggingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright 2026 The Terasology Foundation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.terasology.crashreporter.pages; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.terasology.crashreporter.GlobalProperties; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.PrintStream; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * Regression test for an upload failure that previously left no trace anywhere once its | ||
| * {@code JOptionPane} was dismissed - found while manually testing the reporter dialog: a real | ||
| * exception (a missing-Jackson {@code NoClassDefFoundError} - see the jackson-bom fix elsewhere in | ||
| * this commit) only ever showed up in a popup, with nothing printed to stderr for whoever launched | ||
| * the process to find afterward. | ||
| */ | ||
| class UploadPanelFailureLoggingTest { | ||
|
|
||
| private PrintStream originalErr; | ||
| private ByteArrayOutputStream capturedErr; | ||
|
|
||
| @BeforeEach | ||
| void redirectStderr() { | ||
| originalErr = System.err; | ||
| capturedErr = new ByteArrayOutputStream(); | ||
| System.setErr(new PrintStream(capturedErr, true, StandardCharsets.UTF_8)); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void restoreStderr() { | ||
| System.setErr(originalErr); | ||
| } | ||
|
|
||
| @Test | ||
| void aFailedUploadIsPrintedToStderrNotJustShownInAPopup() throws InterruptedException { | ||
| UploadPanel panel = new UploadPanel(new GlobalProperties(), () -> "log text", () -> "log.txt"); | ||
|
|
||
| final Exception cause = new IllegalStateException("upload failed: missing Jackson class"); | ||
| panel.uploadForTesting(new Callable<URL>() { | ||
| @Override | ||
| public URL call() throws Exception { | ||
| throw cause; | ||
| } | ||
| }); | ||
|
|
||
| long deadline = System.currentTimeMillis() + 2000; | ||
| while (capturedErr.size() == 0 && System.currentTimeMillis() < deadline) { | ||
| Thread.sleep(20); | ||
| } | ||
|
|
||
| String stderr = capturedErr.toString(StandardCharsets.UTF_8); | ||
| assertTrue(stderr.contains("IllegalStateException"), "Expected the exception type on stderr, got: " + stderr); | ||
| assertTrue(stderr.contains("upload failed: missing Jackson class"), | ||
| "Expected the exception message on stderr, got: " + stderr); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not particularly helpful. The rationale for the change belongs in the pull request description.