mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
Merge pull request #4794 from facchinm/upload_fail_handling
Handling gracefully upload failure
This commit is contained in:
commit
1a6be715ab
@ -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,14 @@ public class Sketch {
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public abstract class Uploader implements MessageConsumer {
|
||||
}
|
||||
|
||||
private void init(boolean nup) {
|
||||
this.error = null;
|
||||
this.error = "";
|
||||
this.notFoundError = false;
|
||||
this.noUploadPort = nup;
|
||||
}
|
||||
@ -146,15 +146,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)) {
|
||||
@ -164,8 +162,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) {
|
||||
|
@ -135,7 +135,7 @@ public class SSHUploader extends Uploader {
|
||||
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")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user