From 63de1cccfb4a0a7d9246e32ccdafc2c0d985e24d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 11 Feb 2016 16:06:55 +0100 Subject: [PATCH] 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 --- app/src/processing/app/Sketch.java | 9 +++++++-- arduino-core/src/cc/arduino/packages/Uploader.java | 13 ++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index ecbd54938..277f4e266 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -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 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; } diff --git a/arduino-core/src/cc/arduino/packages/Uploader.java b/arduino-core/src/cc/arduino/packages/Uploader.java index d58d29504..7b547bb59 100644 --- a/arduino-core/src/cc/arduino/packages/Uploader.java +++ b/arduino-core/src/cc/arduino/packages/Uploader.java @@ -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) {