Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: pkg/barback/lib/src/transform_node.dart

Issue 195993005: Don't pass an asset through a transformer that produces an error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.transform_node; 5 library barback.transform_node;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.dart';
10 import 'asset_id.dart'; 10 import 'asset_id.dart';
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 /// 121 ///
122 /// This causes all of the transform's outputs to be marked as removed as 122 /// This causes all of the transform's outputs to be marked as removed as
123 /// well. Normally this will be automatically done internally based on events 123 /// well. Normally this will be automatically done internally based on events
124 /// from the primary input, but it's possible for a transform to no longer be 124 /// from the primary input, but it's possible for a transform to no longer be
125 /// valid even if its primary input still exists. 125 /// valid even if its primary input still exists.
126 void remove() { 126 void remove() {
127 _onAssetController.close(); 127 _onAssetController.close();
128 _onDoneController.close(); 128 _onDoneController.close();
129 _primarySubscription.cancel(); 129 _primarySubscription.cancel();
130 _clearInputSubscriptions(); 130 _clearInputSubscriptions();
131 for (var controller in _outputControllers.values) { 131 _clearOutputs();
132 controller.setRemoved();
133 }
134 if (_passThroughController != null) { 132 if (_passThroughController != null) {
135 _passThroughController.setRemoved(); 133 _passThroughController.setRemoved();
136 _passThroughController = null; 134 _passThroughController = null;
137 } 135 }
138 } 136 }
139 137
140 /// If [transformer] is lazy, ensures that its concrete outputs will be 138 /// If [transformer] is lazy, ensures that its concrete outputs will be
141 /// generated. 139 /// generated.
142 void force() { 140 void force() {
143 // TODO(nweiz): we might want to have a timeout after which, if the 141 // TODO(nweiz): we might want to have a timeout after which, if the
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 phase.cascade.reportError(error); 195 phase.cascade.reportError(error);
198 196
199 return false; 197 return false;
200 }).then((isPrimary) { 198 }).then((isPrimary) {
201 if (_isRemoved) return; 199 if (_isRemoved) return;
202 if (_state.needsIsPrimary) { 200 if (_state.needsIsPrimary) {
203 _process(); 201 _process();
204 } else if (isPrimary) { 202 } else if (isPrimary) {
205 _apply(); 203 _apply();
206 } else { 204 } else {
207 _doesNotApply(); 205 _clearOutputs();
206 _emitPassThrough();
208 _state = _TransformNodeState.NOT_PRIMARY; 207 _state = _TransformNodeState.NOT_PRIMARY;
209 _onDoneController.add(null); 208 _onDoneController.add(null);
210 } 209 }
211 }); 210 });
212 } 211 }
213 212
214 /// Applies this transform. 213 /// Applies this transform.
215 void _apply() { 214 void _apply() {
216 assert(!_onAssetController.isClosed); 215 assert(!_onAssetController.isClosed);
217 216
(...skipping 15 matching lines...) Expand all
233 if (!_state.isProcessing || _isRemoved) return; 232 if (!_state.isProcessing || _isRemoved) return;
234 233
235 if (error is! MissingInputException) { 234 if (error is! MissingInputException) {
236 error = new TransformerException(info, error, stackTrace); 235 error = new TransformerException(info, error, stackTrace);
237 } 236 }
238 237
239 // Catch all transformer errors and pipe them to the results stream. This 238 // Catch all transformer errors and pipe them to the results stream. This
240 // is so a broken transformer doesn't take down the whole graph. 239 // is so a broken transformer doesn't take down the whole graph.
241 phase.cascade.reportError(error); 240 phase.cascade.reportError(error);
242 241
243 _doesNotApply(); 242 _clearOutputs();
243 _dontEmitPassThrough();
244 }).then((_) { 244 }).then((_) {
245 if (_isRemoved) return; 245 if (_isRemoved) return;
246 246
247 if (_state.needsIsPrimary) { 247 if (_state.needsIsPrimary) {
248 _process(); 248 _process();
249 } else if (_state.needsApply) { 249 } else if (_state.needsApply) {
250 _apply(); 250 _apply();
251 } else { 251 } else {
252 assert(_state.isProcessing); 252 assert(_state.isProcessing);
253 _state = _TransformNodeState.APPLIED; 253 _state = _TransformNodeState.APPLIED;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 378 }
379 379
380 /// Cancels all subscriptions to secondary input nodes. 380 /// Cancels all subscriptions to secondary input nodes.
381 void _clearInputSubscriptions() { 381 void _clearInputSubscriptions() {
382 for (var subscription in _inputSubscriptions.values) { 382 for (var subscription in _inputSubscriptions.values) {
383 subscription.cancel(); 383 subscription.cancel();
384 } 384 }
385 _inputSubscriptions.clear(); 385 _inputSubscriptions.clear();
386 } 386 }
387 387
388 /// Marks this transformer as not applying to [primary]. 388 /// Removes all output assets.
389 /// 389 void _clearOutputs() {
390 /// This might be because [primary] isn't primary for [transformer], or
391 /// because [transformer] threw an error during [transformer.apply].
392 void _doesNotApply() {
393 // Remove all the previously-emitted assets. 390 // Remove all the previously-emitted assets.
394 for (var controller in _outputControllers.values) { 391 for (var controller in _outputControllers.values) {
395 controller.setRemoved(); 392 controller.setRemoved();
396 } 393 }
397 _outputControllers.clear(); 394 _outputControllers.clear();
398 _emitPassThrough();
399 } 395 }
400 396
401 /// Emit the pass-through asset if it's not being emitted already. 397 /// Emit the pass-through asset if it's not being emitted already.
402 void _emitPassThrough() { 398 void _emitPassThrough() {
403 assert(!_outputControllers.containsKey(primary.id)); 399 assert(!_outputControllers.containsKey(primary.id));
404 400
405 if (_consumePrimary) return; 401 if (_consumePrimary) return;
406 if (_passThroughController == null) { 402 if (_passThroughController == null) {
407 _passThroughController = new AssetNodeController.from(primary); 403 _passThroughController = new AssetNodeController.from(primary);
408 _onAssetController.add(_passThroughController.node); 404 _onAssetController.add(_passThroughController.node);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 /// 479 ///
484 /// Specifically, whether [this] is [APPLIED] or [NOT_PRIMARY]. 480 /// Specifically, whether [this] is [APPLIED] or [NOT_PRIMARY].
485 bool get isDone => isApplied || isNotPrimary; 481 bool get isDone => isApplied || isNotPrimary;
486 482
487 final String name; 483 final String name;
488 484
489 const _TransformNodeState._(this.name); 485 const _TransformNodeState._(this.name);
490 486
491 String toString() => name; 487 String toString() => name;
492 } 488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698