Skip to content

Commit 108f5cc

Browse files
authored
Merge pull request #5486 from JakubValtar/fix-status-exception
Fix sketch exception getting hidden by warning
2 parents 50af488 + eb90025 commit 108f5cc

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package processing.app;
2+
3+
import java.awt.EventQueue;
4+
5+
public class RunnerListenerEdtAdapter implements RunnerListener {
6+
7+
private RunnerListener wrapped;
8+
9+
public RunnerListenerEdtAdapter(RunnerListener wrapped) {
10+
this.wrapped = wrapped;
11+
}
12+
13+
@Override
14+
public void statusError(String message) {
15+
EventQueue.invokeLater(() -> wrapped.statusError(message));
16+
}
17+
18+
@Override
19+
public void statusError(Exception exception) {
20+
EventQueue.invokeLater(() -> wrapped.statusError(exception));
21+
}
22+
23+
@Override
24+
public void statusNotice(String message) {
25+
EventQueue.invokeLater(() -> wrapped.statusNotice(message));
26+
}
27+
28+
@Override
29+
public void startIndeterminate() {
30+
EventQueue.invokeLater(() -> wrapped.startIndeterminate());
31+
}
32+
33+
@Override
34+
public void stopIndeterminate() {
35+
EventQueue.invokeLater(() -> wrapped.stopIndeterminate());
36+
}
37+
38+
@Override
39+
public void statusHalt() {
40+
EventQueue.invokeLater(() -> wrapped.statusHalt());
41+
}
42+
43+
@Override
44+
public boolean isHalted() {
45+
return wrapped.isHalted();
46+
}
47+
}
48+

app/src/processing/app/SketchException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public void hideStackTrace() {
130130
}
131131

132132

133+
public boolean isStackTraceEnabled() {
134+
return showStackTrace;
135+
}
136+
137+
133138
/**
134139
* Nix the java.lang crap out of an exception message
135140
* because it scares the children.

app/src/processing/app/ui/Editor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,17 @@ public void statusError(Exception e) {
29002900

29012901
if (e instanceof SketchException) {
29022902
SketchException re = (SketchException) e;
2903+
2904+
// Make sure something is printed into the console
2905+
// Status bar is volatile
2906+
if (!re.isStackTraceEnabled()) {
2907+
System.err.println(re.getMessage());
2908+
}
2909+
2910+
// Move the cursor to the line before updating the status bar, otherwise
2911+
// status message might get hidden by a potential message caused by moving
2912+
// the cursor to a line with warning in it
2913+
29032914
if (re.hasCodeIndex()) {
29042915
sketch.setCurrentCode(re.getCodeIndex());
29052916
}

java/src/processing/mode/java/Debugger.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javax.swing.tree.DefaultMutableTreeNode;
4040

4141
import processing.app.Messages;
42+
import processing.app.RunnerListenerEdtAdapter;
4243
import processing.app.Sketch;
4344
import processing.app.SketchCode;
4445
import processing.mode.java.debug.*;
@@ -201,7 +202,7 @@ public synchronized void startDebug() {
201202
//lineMap = LineMapping.generateMapping(srcPath + File.separator + mainClassName + ".java");
202203

203204
log("launching debuggee runtime");
204-
runtime = new Runner(build, editor);
205+
runtime = new Runner(build, new RunnerListenerEdtAdapter(editor));
205206
VirtualMachine vm = runtime.debug(null); // non-blocking
206207
if (vm == null) {
207208
loge("error 37: launch failed", null);

java/src/processing/mode/java/JavaEditor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,11 @@ protected void handleLaunch(boolean present, boolean tweak) {
10941094
synchronized (runtimeLock) {
10951095
if (runtimeLaunchRequested) {
10961096
runtimeLaunchRequested = false;
1097+
RunnerListener listener = new RunnerListenerEdtAdapter(JavaEditor.this);
10971098
if (!tweak) {
1098-
runtime = jmode.handleLaunch(sketch, JavaEditor.this, present);
1099+
runtime = jmode.handleLaunch(sketch, listener, present);
10991100
} else {
1100-
runtime = jmode.handleTweak(sketch, JavaEditor.this);
1101+
runtime = jmode.handleTweak(sketch, listener);
11011102
}
11021103
}
11031104
}

0 commit comments

Comments
 (0)