Skip to content

Commit 0a3b82a

Browse files
Improve error handling for files on the commandline
Previously, any files that were specified on the commandline but could not be opened were silently ignored. Only if --verify and --upload was specified and _all_ files failed to open, a generic error message was shown. Additionally, if multiple files were specified with --verify or --upload, only the first would be acted on (the others would be openened and shown in the GUI, but not actually verified or uploaded). Now, whenever a file fails to open, an error message is shown (fatal with --verify or --upload, non-fatal otherwise). Furthermore, with --verify or --upload an error is shown when there is not exactly one file on the commandline. Finally, instead of keeping an "opened" variable, the code now just checks the size of "editors" to see if a blank sketch should be opened.
1 parent 400ae7f commit 0a3b82a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

app/src/processing/app/Base.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ public Base(String[] args) throws Exception {
318318
// Setup board-dependent variables.
319319
onBoardOrPortChange();
320320

321-
boolean opened = false;
322321
boolean doUpload = false;
323322
boolean doVerify = false;
324323
boolean doVerbose = false;
@@ -365,6 +364,9 @@ public Base(String[] args) throws Exception {
365364
filenames.add(args[i]);
366365
}
367366

367+
if ((doUpload || doVerify) && filenames.size() != 1)
368+
showError(null, _("Must specify exactly one sketch file"), null);
369+
368370
for (String path: filenames) {
369371
// Fix a problem with systems that use a non-ASCII languages. Paths are
370372
// being passed in with 8.3 syntax, which makes the sketch loader code
@@ -378,20 +380,22 @@ public Base(String[] args) throws Exception {
378380
e.printStackTrace();
379381
}
380382
}
383+
381384
if (!new File(path).isAbsolute()) {
382385
path = new File(currentDirectory, path).getAbsolutePath();
383386
}
384-
if (handleOpen(path) != null) {
385-
opened = true;
387+
388+
if (handleOpen(path) == null) {
389+
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
390+
// Open failure is fatal in upload/verify mode
391+
if (doUpload || doVerify)
392+
showError(null, mess, null);
393+
else
394+
showWarning(null, mess, null);
386395
}
387396
}
388397

389398
if (doUpload || doVerify) {
390-
if (!opened) {
391-
System.out.println(_("Can't open source sketch!"));
392-
System.exit(2);
393-
}
394-
395399
// Set verbosity for command line build
396400
Preferences.set("build.verbose", "" + doVerbose);
397401
Preferences.set("upload.verbose", "" + doVerbose);
@@ -425,11 +429,10 @@ public Base(String[] args) throws Exception {
425429
}
426430

427431
// Check if there were previously opened sketches to be restored
428-
if (restoreSketches())
429-
opened = true;
432+
restoreSketches();
430433

431434
// Create a new empty window (will be replaced with any files to be opened)
432-
if (!opened) {
435+
if (editors.isEmpty()) {
433436
handleNew();
434437
}
435438

0 commit comments

Comments
 (0)