@@ -500,17 +500,33 @@ class ProcessRunner {
500500 ///
501501 /// If [exitOnError] is set to `true` , then this will throw an error if
502502 /// the [executable] terminates with a non-zero exit code.
503+ /// Defaults to `false` .
504+ ///
505+ /// If [logOnError] is set to `true` , it will print a formatted message about the error.
506+ /// Defaults to `false`
503507 ///
504508 /// Returns the [io.ProcessResult] of the [executable] .
505509 Future <io.ProcessResult > run (String executable, List <String > args,
506510 {Directory workingDir,
507511 bool exitOnError = false ,
512+ bool logOnError = false ,
508513 Encoding stdoutEncoding = io.systemEncoding,
509514 Encoding stderrEncoding = io.systemEncoding}) async {
510- return io.Process .run (executable, args,
515+ final io. ProcessResult result = await io.Process .run (executable, args,
511516 workingDirectory: workingDir? .path,
512517 stdoutEncoding: stdoutEncoding,
513518 stderrEncoding: stderrEncoding);
519+ if (result.exitCode != 0 ) {
520+ if (logOnError) {
521+ final String error =
522+ _getErrorString (executable, args, workingDir: workingDir);
523+ print ('$error Stderr:\n ${result .stdout }' );
524+ }
525+ if (exitOnError) {
526+ throw ToolExit (result.exitCode);
527+ }
528+ }
529+ return result;
514530 }
515531
516532 /// Starts the [executable] with [args] .
@@ -526,31 +542,6 @@ class ProcessRunner {
526542 return process;
527543 }
528544
529- /// Run the [executable] with [args] , throwing an error on non-zero exit code.
530- ///
531- /// Unlike [runAndStream] , this does not stream the process output to stdout.
532- /// It also unconditionally throws an error on a non-zero exit code.
533- ///
534- /// The current working directory of [executable] can be overridden by
535- /// passing [workingDir] .
536- ///
537- /// Returns the [io.ProcessResult] of running the [executable] .
538- Future <io.ProcessResult > runAndExitOnError (
539- String executable,
540- List <String > args, {
541- Directory workingDir,
542- }) async {
543- final io.ProcessResult result = await io.Process .run (executable, args,
544- workingDirectory: workingDir? .path);
545- if (result.exitCode != 0 ) {
546- final String error =
547- _getErrorString (executable, args, workingDir: workingDir);
548- print ('$error Stderr:\n ${result .stdout }' );
549- throw ToolExit (result.exitCode);
550- }
551- return result;
552- }
553-
554545 String _getErrorString (String executable, List <String > args,
555546 {Directory workingDir}) {
556547 final String workdir = workingDir == null ? '' : ' in ${workingDir .path }' ;
0 commit comments