Skip to content

Commit 1a6be71

Browse files
committed
Merge pull request #4794 from facchinm/upload_fail_handling
Handling gracefully upload failure
2 parents 6521a7a + 0584b2c commit 1a6be71

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

app/src/processing/app/Sketch.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,8 @@ private boolean exportApplet(String appletPath, boolean usingProgrammer)
11641164

11651165
private boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
11661166

1167-
Uploader uploader = new UploaderUtils().getUploaderByPreferences(false);
1167+
UploaderUtils uploaderInstance = new UploaderUtils();
1168+
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);
11681169

11691170
boolean success = false;
11701171
do {
@@ -1183,7 +1184,7 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin
11831184

11841185
List<String> warningsAccumulator = new LinkedList<>();
11851186
try {
1186-
success = new UploaderUtils().upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
1187+
success = uploaderInstance.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
11871188
} finally {
11881189
if (uploader.requiresAuthorization() && !success) {
11891190
PreferencesData.remove(uploader.getAuthorizationKey());
@@ -1198,6 +1199,14 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin
11981199

11991200
} while (uploader.requiresAuthorization() && !success);
12001201

1202+
if (!success) {
1203+
String errorMessage = uploader.getFailureMessage();
1204+
if (errorMessage.equals("")) {
1205+
errorMessage = tr("An error occurred while uploading the sketch");
1206+
}
1207+
editor.statusError(errorMessage);
1208+
}
1209+
12011210
return success;
12021211
}
12031212

arduino-core/src/cc/arduino/packages/Uploader.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected Uploader(boolean nup) {
8989
}
9090

9191
private void init(boolean nup) {
92-
this.error = null;
92+
this.error = "";
9393
this.notFoundError = false;
9494
this.noUploadPort = nup;
9595
}
@@ -146,15 +146,13 @@ protected boolean executeUploadCommand(String command[]) throws Exception {
146146
e.printStackTrace();
147147
}
148148

149-
if (error != null) {
150-
RunnerException exception = new RunnerException(error);
151-
exception.hideStackTrace();
152-
throw exception;
153-
}
154-
155149
return result == 0;
156150
}
157151

152+
public String getFailureMessage() {
153+
return error;
154+
}
155+
158156
public void message(String s) {
159157
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
160158
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
@@ -164,8 +162,9 @@ public void message(String s) {
164162
System.err.print(s);
165163

166164
// ignore cautions
167-
if (s.contains("Error")) {
165+
if (s.toLowerCase().contains("error")) {
168166
notFoundError = true;
167+
error = s;
169168
return;
170169
}
171170
if (notFoundError) {

arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
135135
return runUploadTool(ssh, prefs);
136136
} catch (JSchException e) {
137137
String message = e.getMessage();
138-
if ("Auth cancel".equals(message) || "Auth fail".equals(message)) {
138+
if (message.contains("Auth cancel") || message.contains("Auth fail") || message.contains("authentication fail")) {
139139
return false;
140140
}
141141
if (e.getMessage().contains("Connection refused")) {

0 commit comments

Comments
 (0)