Skip to content

Commit a65f577

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 a9ed40a commit a65f577

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
@@ -139,15 +139,13 @@ protected boolean executeUploadCommand(String command[]) throws Exception {
139139
e.printStackTrace();
140140
}
141141

142-
if (error != null) {
143-
RunnerException exception = new RunnerException(error);
144-
exception.hideStackTrace();
145-
throw exception;
146-
}
147-
148142
return result == 0;
149143
}
150144

145+
public String getFailureMessage() {
146+
return error;
147+
}
148+
151149
public void message(String s) {
152150
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
153151
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
@@ -157,8 +155,9 @@ public void message(String s) {
157155
System.err.print(s);
158156

159157
// ignore cautions
160-
if (s.contains("Error")) {
158+
if (s.toLowerCase().contains("error")) {
161159
notFoundError = true;
160+
error = s;
162161
return;
163162
}
164163
if (notFoundError) {

0 commit comments

Comments
 (0)