@@ -345,41 +345,41 @@ public Base(String[] args) throws Exception {
345
345
if (i < args .length )
346
346
selectBoard = args [i ];
347
347
else
348
- showError (null , "Argument required for --board" , null );
348
+ showError (null , "Argument required for --board" , 3 );
349
349
continue ;
350
350
}
351
351
if (args [i ].equals ("--port" )) {
352
352
i ++;
353
353
if (i < args .length )
354
354
selectPort = args [i ];
355
355
else
356
- showError (null , "Argument required for --port" , null );
356
+ showError (null , "Argument required for --port" , 3 );
357
357
continue ;
358
358
}
359
359
if (args [i ].equals ("--curdir" )) {
360
360
i ++;
361
361
if (i < args .length )
362
362
currentDirectory = args [i ];
363
363
else
364
- showError (null , "Argument required for --curdir" , null );
364
+ showError (null , "Argument required for --curdir" , 3 );
365
365
continue ;
366
366
}
367
367
if (args [i ].equals ("--pref" )) {
368
368
i ++;
369
369
if (i < args .length )
370
370
processPrefArgument (args [i ]);
371
371
else
372
- showError (null , "Argument required for --pref" , null );
372
+ showError (null , "Argument required for --pref" , 3 );
373
373
continue ;
374
374
}
375
375
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 );
377
377
378
378
filenames .add (args [i ]);
379
379
}
380
380
381
381
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 );
383
383
384
384
for (String path : filenames ) {
385
385
// Fix a problem with systems that use a non-ASCII languages. Paths are
@@ -403,7 +403,7 @@ public Base(String[] args) throws Exception {
403
403
String mess = I18n .format (_ ("Failed to open sketch: \" {0}\" " ), path );
404
404
// Open failure is fatal in upload/verify mode
405
405
if (doUpload || doVerify )
406
- showError (null , mess , null );
406
+ showError (null , mess , 2 );
407
407
else
408
408
showWarning (null , mess , null );
409
409
}
@@ -460,22 +460,22 @@ protected void processBoardArgument(String selectBoard) {
460
460
String [] split = selectBoard .split (":" , 4 );
461
461
462
462
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 );
464
464
}
465
465
466
466
TargetPackage targetPackage = getTargetPackage (split [0 ]);
467
467
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 );
469
469
}
470
470
471
471
TargetPlatform targetPlatform = targetPackage .get (split [1 ]);
472
472
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 );
474
474
}
475
475
476
476
TargetBoard targetBoard = targetPlatform .getBoard (split [2 ]);
477
477
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 );
479
479
}
480
480
481
481
selectBoard (targetBoard );
@@ -486,14 +486,14 @@ protected void processBoardArgument(String selectBoard) {
486
486
String [] keyValue = option .split ("=" , 2 );
487
487
488
488
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 );
490
490
String key = keyValue [0 ].trim ();
491
491
String value = keyValue [1 ].trim ();
492
492
493
493
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 );
495
495
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 );
497
497
498
498
Preferences .set ("custom_" + key , targetBoard .getId () + "_" + value );
499
499
}
@@ -503,7 +503,7 @@ protected void processBoardArgument(String selectBoard) {
503
503
protected void processPrefArgument (String arg ) {
504
504
String [] split = arg .split ("=" , 2 );
505
505
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 );
507
507
508
508
Preferences .set (split [0 ], split [1 ]);
509
509
}
@@ -2418,12 +2418,20 @@ static public void showWarning(String title, String message, Exception e) {
2418
2418
}
2419
2419
2420
2420
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
+
2421
2429
/**
2422
2430
* Show an error message that's actually fatal to the program.
2423
2431
* This is an error that can't be recovered. Use showWarning()
2424
2432
* for errors that allow P5 to continue running.
2425
2433
*/
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 ) {
2427
2435
if (title == null ) title = _ ("Error" );
2428
2436
2429
2437
if (commandLine ) {
@@ -2434,7 +2442,7 @@ static public void showError(String title, String message, Throwable e) {
2434
2442
JOptionPane .ERROR_MESSAGE );
2435
2443
}
2436
2444
if (e != null ) e .printStackTrace ();
2437
- System .exit (1 );
2445
+ System .exit (exit_code );
2438
2446
}
2439
2447
2440
2448
0 commit comments