From 8f524e14a598682e470ed5b9448da8a82680172e Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 4 Feb 2016 11:46:28 +0100 Subject: [PATCH 1/4] fix exception if remote upload fails on newer ssh client --- arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java index b0ba1ec4ee9..cc0a1080827 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java @@ -135,7 +135,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String return runUploadTool(ssh, prefs); } catch (JSchException e) { String message = e.getMessage(); - if ("Auth cancel".equals(message) || "Auth fail".equals(message)) { + if (message.contains("Auth cancel") || message.contains("Auth fail") || message.contains("authentication fail")) { return false; } if (e.getMessage().contains("Connection refused")) { From 63de1cccfb4a0a7d9246e32ccdafc2c0d985e24d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 11 Feb 2016 16:06:55 +0100 Subject: [PATCH 2/4] 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 ecbd54938a6..277f4e2667e 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1164,7 +1164,8 @@ private boolean exportApplet(String appletPath, boolean usingProgrammer) 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 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin 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 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin } 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 d58d29504f5..7b547bb596f 100644 --- a/arduino-core/src/cc/arduino/packages/Uploader.java +++ b/arduino-core/src/cc/arduino/packages/Uploader.java @@ -130,15 +130,13 @@ protected boolean executeUploadCommand(String command[]) throws Exception { 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 void message(String s) { System.err.print(s); // ignore cautions - if (s.contains("Error")) { + if (s.toLowerCase().contains("error")) { notFoundError = true; + error = s; return; } if (notFoundError) { From 84ebc68af7f9f5b3e71a361aaf65a79c3eef7b75 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 11 Feb 2016 16:45:42 +0100 Subject: [PATCH 3/4] Handle case with empty error message --- app/src/processing/app/Sketch.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 277f4e2667e..7bb7dee11e6 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1200,7 +1200,11 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin } while (uploader.requiresAuthorization() && !success); if (!success) { - editor.statusError(uploader.getFailureMessage()); + String errorMessage = uploader.getFailureMessage(); + if (errorMessage.equals("")) { + errorMessage = tr("An error occurred while uploading the sketch"); + } + editor.statusError(errorMessage); } return success; From 0584b2c2bd8d6c0f72fe62ebd16cff13bcbc150b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 15 Feb 2016 17:10:46 +0100 Subject: [PATCH 4/4] initialize the error string as empty (not null) --- arduino-core/src/cc/arduino/packages/Uploader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/packages/Uploader.java b/arduino-core/src/cc/arduino/packages/Uploader.java index 7b547bb596f..a93734ed6a6 100644 --- a/arduino-core/src/cc/arduino/packages/Uploader.java +++ b/arduino-core/src/cc/arduino/packages/Uploader.java @@ -85,7 +85,7 @@ protected Uploader(boolean nup) { } private void init(boolean nup) { - this.error = null; + this.error = ""; this.notFoundError = false; this.noUploadPort = nup; }