From 0a3b82af8f5c605892b243c2dbcd3395981248b4 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 25 Oct 2013 15:38:28 +0200 Subject: [PATCH] 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. --- app/src/processing/app/Base.java | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 05b173b2a..92d54f020 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -318,7 +318,6 @@ public class Base { // Setup board-dependent variables. onBoardOrPortChange(); - boolean opened = false; boolean doUpload = false; boolean doVerify = false; boolean doVerbose = false; @@ -365,6 +364,9 @@ public class Base { filenames.add(args[i]); } + if ((doUpload || doVerify) && filenames.size() != 1) + showError(null, _("Must specify exactly one sketch file"), null); + for (String path: filenames) { // Fix a problem with systems that use a non-ASCII languages. Paths are // being passed in with 8.3 syntax, which makes the sketch loader code @@ -378,20 +380,22 @@ public class Base { e.printStackTrace(); } } + if (!new File(path).isAbsolute()) { path = new File(currentDirectory, path).getAbsolutePath(); } - if (handleOpen(path) != null) { - opened = true; + + if (handleOpen(path) == null) { + String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path); + // Open failure is fatal in upload/verify mode + if (doUpload || doVerify) + showError(null, mess, null); + else + showWarning(null, mess, null); } } if (doUpload || doVerify) { - if (!opened) { - System.out.println(_("Can't open source sketch!")); - System.exit(2); - } - // Set verbosity for command line build Preferences.set("build.verbose", "" + doVerbose); Preferences.set("upload.verbose", "" + doVerbose); @@ -425,11 +429,10 @@ public class Base { } // Check if there were previously opened sketches to be restored - if (restoreSketches()) - opened = true; + restoreSketches(); // Create a new empty window (will be replaced with any files to be opened) - if (!opened) { + if (editors.isEmpty()) { handleNew(); }