Skip to content

Handling gracefully upload failure #4794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -1183,7 +1184,7 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin

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());
Expand All @@ -1198,6 +1199,14 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin

} 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;
}

Expand Down
15 changes: 7 additions & 8 deletions arduino-core/src/cc/arduino/packages/Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected Uploader(boolean nup) {
}

private void init(boolean nup) {
this.error = null;
this.error = "";
this.notFoundError = false;
this.noUploadPort = nup;
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down