Add failOk to WorkerJob to avoid printing failure messages for failed jobs.
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a06f22..6eca3d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md
@@ -1,5 +1,10 @@ # Change Log for `process_runner` +## 2.0.5 + +* Added `WorkerJob.failOk` so that failure message of failed worker jobs is + suppressed by default, but can be turned on. + ## 2.0.4 * Added `printOutputDefault` to the `ProcessRunner` constructor, and updated
diff --git a/lib/src/process_pool.dart b/lib/src/process_pool.dart index 7d96c89..a0256f1 100644 --- a/lib/src/process_pool.dart +++ b/lib/src/process_pool.dart
@@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:convert' show Encoding; -import 'dart:io' show Directory, Platform, stdout, SystemEncoding; +import 'dart:io' show Directory, Platform, stdout, SystemEncoding, stderr; import 'package:async/async.dart' show StreamGroup; @@ -22,7 +22,10 @@ this.printOutput = false, this.stdin, this.stdinRaw, - }) : name = name ?? command.join(' '); + this.failOk = true, + }) : assert(failOk != null), + assert(printOutput != null), + name = name ?? command.join(' '); /// The name of the job. /// @@ -54,6 +57,12 @@ /// Whether or not this command should print it's stdout when it runs. final bool printOutput; + /// Whether or not failure of this job should print a message to stderr or + /// not. + /// + /// Defaults to true, since the [result] will contain the exit code. + final bool failOk; + /// Once the job is complete, this contains the result of the job. /// /// The [stderr], [stdout], and [output] accessors will decode their raw @@ -174,10 +183,13 @@ workingDirectory: job.workingDirectory, printOutput: job.printOutput, stdin: job.stdinRaw ?? (job.stdin != null ? encoding.encoder.bind(job.stdin) : null), + failOk: false, // Must be false so that we can catch the exception below. ); _completedJobs.add(job); } on ProcessRunnerException catch (e) { - print('\nJob $job failed: $e'); + if (!job.failOk) { + stderr.writeln('\nJob $job failed: $e'); + } _failedJobs.add(job); } finally { _inProgressJobs--;
diff --git a/pubspec.yaml b/pubspec.yaml index 6098819..1476a39 100644 --- a/pubspec.yaml +++ b/pubspec.yaml
@@ -3,7 +3,7 @@ # found in the LICENSE file. name: process_runner -version: 2.0.4 +version: 2.0.5 description: A process invocation astraction for Dart that manages a multiprocess queue. homepage: https://github.com/google/process_runner