Merge pull request #4794 from facchinm/upload_fail_handling

Handling gracefully upload failure
This commit is contained in:
Sandeep Mistry 2016-07-20 10:18:57 -04:00
commit 1a6be715ab
3 changed files with 19 additions and 11 deletions

View File

@ -1164,7 +1164,8 @@ public class Sketch {
private boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception { 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; boolean success = false;
do { do {
@ -1183,7 +1184,7 @@ public class Sketch {
List<String> warningsAccumulator = new LinkedList<>(); List<String> warningsAccumulator = new LinkedList<>();
try { try {
success = new UploaderUtils().upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator); success = uploaderInstance.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
} finally { } finally {
if (uploader.requiresAuthorization() && !success) { if (uploader.requiresAuthorization() && !success) {
PreferencesData.remove(uploader.getAuthorizationKey()); PreferencesData.remove(uploader.getAuthorizationKey());
@ -1198,6 +1199,14 @@ public class Sketch {
} while (uploader.requiresAuthorization() && !success); } while (uploader.requiresAuthorization() && !success);
if (!success) {
String errorMessage = uploader.getFailureMessage();
if (errorMessage.equals("")) {
errorMessage = tr("An error occurred while uploading the sketch");
}
editor.statusError(errorMessage);
}
return success; return success;
} }

View File

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

View File

@ -135,7 +135,7 @@ public class SSHUploader extends Uploader {
return runUploadTool(ssh, prefs); return runUploadTool(ssh, prefs);
} catch (JSchException e) { } catch (JSchException e) {
String message = e.getMessage(); 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; return false;
} }
if (e.getMessage().contains("Connection refused")) { if (e.getMessage().contains("Connection refused")) {