Skip to content

Commit cede268

Browse files
committed
Fix 'Select port on upload' error message
1 parent 2397e1e commit cede268

File tree

5 files changed

+30
-40
lines changed

5 files changed

+30
-40
lines changed

app/src/processing/app/Editor.java

+2
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,8 @@ private void handleBurnBootloader() {
23452345
SwingUtilities.invokeLater(() -> statusError(tr("Error while burning bootloader.")));
23462346
// error message will already be visible
23472347
}
2348+
} catch (SerialNotFoundException e) {
2349+
SwingUtilities.invokeLater(() -> statusError(tr("Error while burning bootloader: please select a serial port.")));
23482350
} catch (PreferencesMapException e) {
23492351
SwingUtilities.invokeLater(() -> {
23502352
statusError(I18n.format(

app/src/processing/app/SketchController.java

-4
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,6 @@ private boolean upload(String suggestedClassName, boolean usingProgrammer) throw
709709

710710
UploaderUtils uploaderInstance = new UploaderUtils();
711711
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);
712-
if (uploader == null) {
713-
editor.statusError(tr("Please select a Port before Upload"));
714-
return false;
715-
}
716712

717713
EditorConsole.setCurrentEditorConsole(editor.console);
718714

arduino-core/src/cc/arduino/UploaderUtils.java

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public Uploader getUploaderByPreferences(boolean noUploadPort) {
4848
BoardPort boardPort = null;
4949
if (!noUploadPort) {
5050
String port = PreferencesData.get("serial.port");
51-
if (port == null || port.isEmpty()) {
52-
return null;
53-
}
5451
boardPort = BaseNoGui.getDiscoveryManager().find(port);
5552
}
5653

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

+26-31
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import processing.app.debug.RunnerException;
4242
import processing.app.debug.TargetPlatform;
4343
import processing.app.helpers.PreferencesMap;
44+
import processing.app.helpers.PreferencesMapException;
4445
import processing.app.helpers.StringReplacer;
4546

4647
import java.io.File;
@@ -105,17 +106,11 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
105106
else
106107
prefs.put("upload.verify", prefs.get("upload.params.noverify", ""));
107108

108-
boolean uploadResult;
109109
try {
110-
String pattern = prefs.getOrExcept("upload.pattern");
111-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
112-
uploadResult = executeUploadCommand(cmd);
113-
} catch (Exception e) {
114-
throw new RunnerException(e);
110+
return runCommand("upload.pattern", prefs);
115111
} finally {
116112
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
117113
}
118-
return uploadResult;
119114
}
120115

121116
// need to do a little dance for Leonardo and derivatives:
@@ -127,7 +122,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
127122
boolean doTouch = prefs.getBoolean("upload.use_1200bps_touch");
128123
boolean waitForUploadPort = prefs.getBoolean("upload.wait_for_upload_port");
129124

130-
String userSelectedUploadPort = prefs.getOrExcept("serial.port");
125+
String userSelectedUploadPort = prefs.get("serial.port", "");
131126
String actualUploadPort = null;
132127

133128
if (doTouch) {
@@ -177,7 +172,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
177172
Thread.sleep(100);
178173
}
179174

180-
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
175+
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port", ""));
181176
try {
182177
prefs.put("serial.port.iserial", boardPort.getPrefs().getOrExcept("iserial"));
183178
} catch (Exception e) {
@@ -199,13 +194,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
199194

200195
boolean uploadResult;
201196
try {
202-
String pattern = prefs.getOrExcept("upload.pattern");
203-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
204-
uploadResult = executeUploadCommand(cmd);
205-
} catch (RunnerException e) {
206-
throw e;
207-
} catch (Exception e) {
208-
throw new RunnerException(e);
197+
uploadResult = runCommand("upload.pattern", prefs);
209198
} finally {
210199
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
211200
}
@@ -328,15 +317,7 @@ private boolean uploadUsingProgrammer(String buildPath, String className) throws
328317
else
329318
prefs.put("program.verify", prefs.get("program.params.noverify", ""));
330319

331-
try {
332-
String pattern = prefs.getOrExcept("program.pattern");
333-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
334-
return executeUploadCommand(cmd);
335-
} catch (RunnerException e) {
336-
throw e;
337-
} catch (Exception e) {
338-
throw new RunnerException(e);
339-
}
320+
return runCommand("program.pattern", prefs);
340321
}
341322

342323
@Override
@@ -393,13 +374,27 @@ public boolean burnBootloader() throws Exception {
393374

394375
new LoadVIDPIDSpecificPreferences().load(prefs);
395376

396-
String pattern = prefs.getOrExcept("erase.pattern");
397-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
398-
if (!executeUploadCommand(cmd))
377+
if (!runCommand("erase.pattern", prefs))
399378
return false;
400379

401-
pattern = prefs.getOrExcept("bootloader.pattern");
402-
cmd = StringReplacer.formatAndSplit(pattern, prefs);
403-
return executeUploadCommand(cmd);
380+
return runCommand("bootloader.pattern", prefs);
381+
}
382+
383+
private boolean runCommand(String patternKey, PreferencesMap prefs) throws Exception, RunnerException {
384+
try {
385+
String pattern = prefs.getOrExcept(patternKey);
386+
StringReplacer.checkIfRequiredKeyIsMissingOrExcept("serial.port", pattern, prefs);
387+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
388+
return executeUploadCommand(cmd);
389+
} catch (RunnerException e) {
390+
throw e;
391+
} catch (PreferencesMapException e) {
392+
if (e.getMessage().equals("serial.port")) {
393+
throw new SerialNotFoundException(e);
394+
}
395+
throw e;
396+
} catch (Exception e) {
397+
throw new RunnerException(e);
398+
}
404399
}
405400
}

build/shared/lib/preferences.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ programmer = arduino:avrispmkii
267267
upload.using = bootloader
268268
upload.verify = true
269269

270-
#default port is empty to prevent running AVRDUDE before Port selected (issue #7943)
271-
serial.port=
270+
# default port is not defined to prevent running AVRDUDE before Port selected (issue #7943)
271+
#serial.port=
272272
serial.databits=8
273273
serial.stopbits=1
274274
serial.parity=N

0 commit comments

Comments
 (0)