Skip to content

Commit 0029e97

Browse files
Return different exit codes with --verify or --upload
Previous commits made all failures return 1, even though originally an unknown sketch file would return 2. This restores the previous behaviour and adds return code 3 to mean invalid options specified. The return codes are now: 0: Success 1: Build failed or upload failed 2: Sketch not found 3: Invalid commandline options
1 parent 9196a8d commit 0029e97

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

app/src/processing/app/Base.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,41 +345,41 @@ public Base(String[] args) throws Exception {
345345
if (i < args.length)
346346
selectBoard = args[i];
347347
else
348-
showError(null, "Argument required for --board", null);
348+
showError(null, "Argument required for --board", 3);
349349
continue;
350350
}
351351
if (args[i].equals("--port")) {
352352
i++;
353353
if (i < args.length)
354354
selectPort = args[i];
355355
else
356-
showError(null, "Argument required for --port", null);
356+
showError(null, "Argument required for --port", 3);
357357
continue;
358358
}
359359
if (args[i].equals("--curdir")) {
360360
i++;
361361
if (i < args.length)
362362
currentDirectory = args[i];
363363
else
364-
showError(null, "Argument required for --curdir", null);
364+
showError(null, "Argument required for --curdir", 3);
365365
continue;
366366
}
367367
if (args[i].equals("--pref")) {
368368
i++;
369369
if (i < args.length)
370370
processPrefArgument(args[i]);
371371
else
372-
showError(null, "Argument required for --pref", null);
372+
showError(null, "Argument required for --pref", 3);
373373
continue;
374374
}
375375
if (args[i].startsWith("--"))
376-
showError(null, I18n.format(_("unknown option: {0}"), args[i]), null);
376+
showError(null, I18n.format(_("unknown option: {0}"), args[i]), 3);
377377

378378
filenames.add(args[i]);
379379
}
380380

381381
if ((doUpload || doVerify) && filenames.size() != 1)
382-
showError(null, _("Must specify exactly one sketch file"), null);
382+
showError(null, _("Must specify exactly one sketch file"), 3);
383383

384384
for (String path: filenames) {
385385
// Fix a problem with systems that use a non-ASCII languages. Paths are
@@ -403,7 +403,7 @@ public Base(String[] args) throws Exception {
403403
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
404404
// Open failure is fatal in upload/verify mode
405405
if (doUpload || doVerify)
406-
showError(null, mess, null);
406+
showError(null, mess, 2);
407407
else
408408
showWarning(null, mess, null);
409409
}
@@ -460,22 +460,22 @@ protected void processBoardArgument(String selectBoard) {
460460
String[] split = selectBoard.split(":", 4);
461461

462462
if (split.length < 3) {
463-
showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), null);
463+
showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
464464
}
465465

466466
TargetPackage targetPackage = getTargetPackage(split[0]);
467467
if (targetPackage == null) {
468-
showError(null, I18n.format(_("{0}: Unknown package"), split[0]), null);
468+
showError(null, I18n.format(_("{0}: Unknown package"), split[0]), 3);
469469
}
470470

471471
TargetPlatform targetPlatform = targetPackage.get(split[1]);
472472
if (targetPlatform == null) {
473-
showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), null);
473+
showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), 3);
474474
}
475475

476476
TargetBoard targetBoard = targetPlatform.getBoard(split[2]);
477477
if (targetBoard == null) {
478-
showError(null, I18n.format(_("{0}: Unknown board"), split[2]), null);
478+
showError(null, I18n.format(_("{0}: Unknown board"), split[2]), 3);
479479
}
480480

481481
selectBoard(targetBoard);
@@ -486,14 +486,14 @@ protected void processBoardArgument(String selectBoard) {
486486
String[] keyValue = option.split("=", 2);
487487

488488
if (keyValue.length != 2)
489-
showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), null);
489+
showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), 3);
490490
String key = keyValue[0].trim();
491491
String value = keyValue[1].trim();
492492

493493
if (!targetBoard.hasMenu(key))
494-
showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), null);
494+
showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), 3);
495495
if (targetBoard.getMenuLabel(key, value) == null)
496-
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), null);
496+
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
497497

498498
Preferences.set("custom_" + key, targetBoard.getId() + "_" + value);
499499
}
@@ -503,7 +503,7 @@ protected void processBoardArgument(String selectBoard) {
503503
protected void processPrefArgument(String arg) {
504504
String[] split = arg.split("=", 2);
505505
if (split.length != 2 || split[0].isEmpty())
506-
showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), null);
506+
showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), 3);
507507

508508
Preferences.set(split[0], split[1]);
509509
}
@@ -2418,12 +2418,20 @@ static public void showWarning(String title, String message, Exception e) {
24182418
}
24192419

24202420

2421+
static public void showError(String title, String message, Throwable e) {
2422+
showError(title, message, e, 1);
2423+
}
2424+
2425+
static public void showError(String title, String message, int exit_code) {
2426+
showError(title, message, null, exit_code);
2427+
}
2428+
24212429
/**
24222430
* Show an error message that's actually fatal to the program.
24232431
* This is an error that can't be recovered. Use showWarning()
24242432
* for errors that allow P5 to continue running.
24252433
*/
2426-
static public void showError(String title, String message, Throwable e) {
2434+
static public void showError(String title, String message, Throwable e, int exit_code) {
24272435
if (title == null) title = _("Error");
24282436

24292437
if (commandLine) {
@@ -2434,7 +2442,7 @@ static public void showError(String title, String message, Throwable e) {
24342442
JOptionPane.ERROR_MESSAGE);
24352443
}
24362444
if (e != null) e.printStackTrace();
2437-
System.exit(1);
2445+
System.exit(exit_code);
24382446
}
24392447

24402448

0 commit comments

Comments
 (0)