Skip to content

Commit bde2f52

Browse files
authored
[web] make Pipeline.run throw (flutter#27340)
* [web] make Pipeline.run throw
1 parent f44af6a commit bde2f52

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

lib/web_ui/dev/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BuildCommand extends Command<bool> with ArgUtils {
3939
GnPipelineStep(),
4040
NinjaPipelineStep(),
4141
]);
42-
await buildPipeline.start();
42+
await buildPipeline.run();
4343

4444
if (isWatchMode) {
4545
print('Initial build done!');

lib/web_ui/dev/test_runner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class TestCommand extends Command<bool> with ArgUtils {
189189
ClearTerminalScreenStep(),
190190
TestRunnerStep(this),
191191
]);
192-
await testPipeline.start();
192+
await testPipeline.run();
193193

194194
if (isWatchMode) {
195195
final FilePath dir = FilePath.fromWebUi('');

lib/web_ui/dev/watcher.dart

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,15 @@ class Pipeline {
104104
PipelineStatus get status => _status;
105105
PipelineStatus _status = PipelineStatus.idle;
106106

107-
/// Starts executing tasks of the pipeline.
107+
/// Runs the steps of the pipeline.
108108
///
109109
/// 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 {
111116
_status = PipelineStatus.started;
112117
try {
113118
for (PipelineStep step in steps) {
@@ -119,10 +124,9 @@ class Pipeline {
119124
await _currentStepFuture;
120125
}
121126
_status = PipelineStatus.done;
122-
} catch (error, stackTrace) {
127+
} catch (_) {
123128
_status = PipelineStatus.error;
124-
print('Error in the pipeline: $error');
125-
print(stackTrace);
129+
rethrow;
126130
} finally {
127131
_currentStep = null;
128132
}
@@ -221,31 +225,38 @@ class PipelineWatcher {
221225
});
222226
}
223227

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);
242248
}
243249
}
244250

245-
void _pipelineDone(int pipelineRunCount) {
251+
void _pipelineSucceeded(int pipelineRunCount) {
246252
if (pipelineRunCount == _pipelineRunCount) {
247253
print('*** Done! ***');
248254
print('Press \'q\' to exit felt');
249255
}
250256
}
257+
258+
void _pipelineFailed(Object error, StackTrace stackTrace) {
259+
print('felt command failed: $error');
260+
print(stackTrace);
261+
}
251262
}

0 commit comments

Comments
 (0)