@@ -104,10 +104,15 @@ class Pipeline {
104
104
PipelineStatus get status => _status;
105
105
PipelineStatus _status = PipelineStatus .idle;
106
106
107
- /// Starts executing tasks of the pipeline.
107
+ /// Runs the steps of the pipeline.
108
108
///
109
109
/// Returns a future that resolves after all steps have been performed.
110
- Future <void > start () async {
110
+ ///
111
+ /// The future resolves to an error as soon as any of the steps fails.
112
+ ///
113
+ /// The pipeline may be interrupted by calling [stop] before the future
114
+ /// resolves.
115
+ Future <void > run () async {
111
116
_status = PipelineStatus .started;
112
117
try {
113
118
for (PipelineStep step in steps) {
@@ -119,10 +124,9 @@ class Pipeline {
119
124
await _currentStepFuture;
120
125
}
121
126
_status = PipelineStatus .done;
122
- } catch (error, stackTrace ) {
127
+ } catch (_ ) {
123
128
_status = PipelineStatus .error;
124
- print ('Error in the pipeline: $error ' );
125
- print (stackTrace);
129
+ rethrow ;
126
130
} finally {
127
131
_currentStep = null ;
128
132
}
@@ -221,31 +225,38 @@ class PipelineWatcher {
221
225
});
222
226
}
223
227
224
- void _runPipeline () {
225
- int runCount;
226
- switch (pipeline.status) {
227
- case PipelineStatus .started:
228
- pipeline.stop ().then ((_) {
229
- runCount = _pipelineRunCount;
230
- pipeline.start ().then ((_) => _pipelineDone (runCount));
231
- });
232
- break ;
233
-
234
- case PipelineStatus .stopping:
235
- // We are already trying to stop the pipeline. No need to do anything.
236
- break ;
237
-
238
- default :
239
- runCount = _pipelineRunCount;
240
- pipeline.start ().then ((_) => _pipelineDone (runCount));
241
- break ;
228
+ void _runPipeline () async {
229
+ if (pipeline.status == PipelineStatus .stopping) {
230
+ // We are already trying to stop the pipeline. No need to do anything.
231
+ return ;
232
+ }
233
+
234
+ if (pipeline.status == PipelineStatus .started) {
235
+ // If the pipeline already running, stop it before starting it again.
236
+ await pipeline.stop ();
237
+ }
238
+
239
+ final int runCount = _pipelineRunCount;
240
+ try {
241
+ await pipeline.run ();
242
+ _pipelineSucceeded (runCount);
243
+ } catch (error, stackTrace) {
244
+ // The error is printed but not rethrown. This is because in watch mode
245
+ // failures are expected. The idea is that the developer corrects the
246
+ // error, saves the file, and the pipeline reruns.
247
+ _pipelineFailed (error, stackTrace);
242
248
}
243
249
}
244
250
245
- void _pipelineDone (int pipelineRunCount) {
251
+ void _pipelineSucceeded (int pipelineRunCount) {
246
252
if (pipelineRunCount == _pipelineRunCount) {
247
253
print ('*** Done! ***' );
248
254
print ('Press \' q\' to exit felt' );
249
255
}
250
256
}
257
+
258
+ void _pipelineFailed (Object error, StackTrace stackTrace) {
259
+ print ('felt command failed: $error ' );
260
+ print (stackTrace);
261
+ }
251
262
}
0 commit comments