Skip to content

Commit 63de1cc

Browse files
committed
Avoid generating an exception if upload fails
The current method of reporting upload errors is based on an exoteric combination of exceptions which makes return error code useless The Uploader.java message() implementation is too avrdude-dependant to allow easy portability since the upload tools are becoming a lot and very different With this commit we try to avoid exceptions and only use the external uploader's exit code to decide the status bar message. The message can be: - the last line containing "error" string (any case) or - the usual avrdude message parsing (to keep compatibility with translations) Needs testing with all platform and all supported upload tools
1 parent 8f524e1 commit 63de1cc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

app/src/processing/app/Sketch.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,8 @@ private boolean exportApplet(String appletPath, boolean usingProgrammer)
11641164

11651165
private boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
11661166

1167-
Uploader uploader = new UploaderUtils().getUploaderByPreferences(false);
1167+
UploaderUtils uploaderInstance = new UploaderUtils();
1168+
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);
11681169

11691170
boolean success = false;
11701171
do {
@@ -1183,7 +1184,7 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin
11831184

11841185
List<String> warningsAccumulator = new LinkedList<>();
11851186
try {
1186-
success = new UploaderUtils().upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
1187+
success = uploaderInstance.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
11871188
} finally {
11881189
if (uploader.requiresAuthorization() && !success) {
11891190
PreferencesData.remove(uploader.getAuthorizationKey());
@@ -1198,6 +1199,10 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin
11981199

11991200
} while (uploader.requiresAuthorization() && !success);
12001201

1202+
if (!success) {
1203+
editor.statusError(uploader.getFailureMessage());
1204+
}
1205+
12011206
return success;
12021207
}
12031208

arduino-core/src/cc/arduino/packages/Uploader.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,13 @@ protected boolean executeUploadCommand(String command[]) throws Exception {
130130
e.printStackTrace();
131131
}
132132

133-
if (error != null) {
134-
RunnerException exception = new RunnerException(error);
135-
exception.hideStackTrace();
136-
throw exception;
137-
}
138-
139133
return result == 0;
140134
}
141135

136+
public String getFailureMessage() {
137+
return error;
138+
}
139+
142140
public void message(String s) {
143141
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
144142
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
@@ -148,8 +146,9 @@ public void message(String s) {
148146
System.err.print(s);
149147

150148
// ignore cautions
151-
if (s.contains("Error")) {
149+
if (s.toLowerCase().contains("error")) {
152150
notFoundError = true;
151+
error = s;
153152
return;
154153
}
155154
if (notFoundError) {

0 commit comments

Comments
 (0)