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
This commit is contained in:
Martino Facchin 2016-02-11 16:06:55 +01:00
parent 8f524e14a5
commit 63de1cccfb
2 changed files with 13 additions and 9 deletions

View File

@ -1164,7 +1164,8 @@ public class Sketch {
private boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
Uploader uploader = new UploaderUtils().getUploaderByPreferences(false);
UploaderUtils uploaderInstance = new UploaderUtils();
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);
boolean success = false;
do {
@ -1183,7 +1184,7 @@ public class Sketch {
List<String> warningsAccumulator = new LinkedList<>();
try {
success = new UploaderUtils().upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
success = uploaderInstance.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
} finally {
if (uploader.requiresAuthorization() && !success) {
PreferencesData.remove(uploader.getAuthorizationKey());
@ -1198,6 +1199,10 @@ public class Sketch {
} while (uploader.requiresAuthorization() && !success);
if (!success) {
editor.statusError(uploader.getFailureMessage());
}
return success;
}

View File

@ -130,15 +130,13 @@ public abstract class Uploader implements MessageConsumer {
e.printStackTrace();
}
if (error != null) {
RunnerException exception = new RunnerException(error);
exception.hideStackTrace();
throw exception;
}
return result == 0;
}
public String getFailureMessage() {
return error;
}
public void message(String s) {
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
@ -148,8 +146,9 @@ public abstract class Uploader implements MessageConsumer {
System.err.print(s);
// ignore cautions
if (s.contains("Error")) {
if (s.toLowerCase().contains("error")) {
notFoundError = true;
error = s;
return;
}
if (notFoundError) {