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

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

Issue 199443003: Asset load failures in Barback should produce AssetNotFoundExceptions. (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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 _clearInputSubscriptions(); 179 _clearInputSubscriptions();
180 _state = _TransformNodeState.PROCESSING; 180 _state = _TransformNodeState.PROCESSING;
181 primary.whenAvailable((_) { 181 primary.whenAvailable((_) {
182 _state = _TransformNodeState.PROCESSING; 182 _state = _TransformNodeState.PROCESSING;
183 return transformer.isPrimary(primary.asset); 183 return transformer.isPrimary(primary.asset);
184 }).catchError((error, stackTrace) { 184 }).catchError((error, stackTrace) {
185 // If the transform became dirty while processing, ignore any errors from 185 // If the transform became dirty while processing, ignore any errors from
186 // it. 186 // it.
187 if (_state.needsIsPrimary || _isRemoved) return false; 187 if (_state.needsIsPrimary || _isRemoved) return false;
188 188
189 if (error is! MissingInputException) {
190 error = new TransformerException(info, error, stackTrace);
191 }
192
193 // Catch all transformer errors and pipe them to the results stream. This 189 // Catch all transformer errors and pipe them to the results stream. This
194 // is so a broken transformer doesn't take down the whole graph. 190 // is so a broken transformer doesn't take down the whole graph.
195 phase.cascade.reportError(error); 191 phase.cascade.reportError(_wrapException(error, stackTrace));
196 192
197 return false; 193 return false;
198 }).then((isPrimary) { 194 }).then((isPrimary) {
199 if (_isRemoved) return; 195 if (_isRemoved) return;
200 if (_state.needsIsPrimary) { 196 if (_state.needsIsPrimary) {
201 _process(); 197 _process();
202 } else if (isPrimary) { 198 } else if (isPrimary) {
203 _apply(); 199 _apply();
204 } else { 200 } else {
205 _clearOutputs(); 201 _clearOutputs();
(...skipping 18 matching lines...) Expand all
224 // TODO(nweiz): If [transformer] is a [DeclaringTransformer] but not a 220 // TODO(nweiz): If [transformer] is a [DeclaringTransformer] but not a
225 // [LazyTransformer], we can get some mileage out of doing a declarative 221 // [LazyTransformer], we can get some mileage out of doing a declarative
226 // first so we know how to hook up the assets. 222 // first so we know how to hook up the assets.
227 if (_isLazy) return _declareLazy(); 223 if (_isLazy) return _declareLazy();
228 return _applyImmediate(); 224 return _applyImmediate();
229 }).catchError((error, stackTrace) { 225 }).catchError((error, stackTrace) {
230 // If the transform became dirty while processing, ignore any errors from 226 // If the transform became dirty while processing, ignore any errors from
231 // it. 227 // it.
232 if (!_state.isProcessing || _isRemoved) return; 228 if (!_state.isProcessing || _isRemoved) return;
233 229
234 if (error is! MissingInputException) {
235 error = new TransformerException(info, error, stackTrace);
236 }
237
238 // Catch all transformer errors and pipe them to the results stream. This 230 // Catch all transformer errors and pipe them to the results stream. This
239 // is so a broken transformer doesn't take down the whole graph. 231 // is so a broken transformer doesn't take down the whole graph.
240 phase.cascade.reportError(error); 232 phase.cascade.reportError(_wrapException(error, stackTrace));
241 233
242 _clearOutputs(); 234 _clearOutputs();
243 _dontEmitPassThrough(); 235 _dontEmitPassThrough();
244 }).then((_) { 236 }).then((_) {
245 if (_isRemoved) return; 237 if (_isRemoved) return;
246 238
247 if (_state.needsIsPrimary) { 239 if (_state.needsIsPrimary) {
248 _process(); 240 _process();
249 } else if (_state.needsApply) { 241 } else if (_state.needsApply) {
250 _apply(); 242 _apply();
251 } else { 243 } else {
252 assert(_state.isProcessing); 244 assert(_state.isProcessing);
253 _state = _TransformNodeState.APPLIED; 245 _state = _TransformNodeState.APPLIED;
254 _onDoneController.add(null); 246 _onDoneController.add(null);
255 } 247 }
256 }); 248 });
257 } 249 }
258 250
259 /// Gets the asset for an input [id]. 251 /// Gets the asset for an input [id].
260 /// 252 ///
261 /// If an input with that ID cannot be found, throws an 253 /// If an input with [id] cannot be found, throws an [AssetNotFoundException].
262 /// [AssetNotFoundException].
263 Future<Asset> getInput(AssetId id) { 254 Future<Asset> getInput(AssetId id) {
264 return phase.getInput(id).then((node) { 255 return phase.getInput(id).then((node) {
265 // Throw if the input isn't found. This ensures the transformer's apply 256 // Throw if the input isn't found. This ensures the transformer's apply
266 // is exited. We'll then catch this and report it through the proper 257 // is exited. We'll then catch this and report it through the proper
267 // results stream. 258 // results stream.
268 if (node == null) throw new MissingInputException(info, id); 259 if (node == null) throw new AssetNotFoundException(id);
269 260
270 _inputSubscriptions.putIfAbsent(node.id, () { 261 _inputSubscriptions.putIfAbsent(node.id, () {
271 return node.onStateChange.listen((_) => _dirty(primaryChanged: false)); 262 return node.onStateChange.listen((_) => _dirty(primaryChanged: false));
272 }); 263 });
273 264
274 return node.asset; 265 return node.asset;
275 }); 266 });
276 } 267 }
277 268
278 /// Applies the transform so that it produces concrete (as opposed to lazy) 269 /// Applies the transform so that it produces concrete (as opposed to lazy)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } 398 }
408 } 399 }
409 400
410 /// Stop emitting the pass-through asset if it's being emitted already. 401 /// Stop emitting the pass-through asset if it's being emitted already.
411 void _dontEmitPassThrough() { 402 void _dontEmitPassThrough() {
412 if (_passThroughController == null) return; 403 if (_passThroughController == null) return;
413 _passThroughController.setRemoved(); 404 _passThroughController.setRemoved();
414 _passThroughController = null; 405 _passThroughController = null;
415 } 406 }
416 407
408 BarbackException _wrapException(error, StackTrace stackTrace) {
409 if (error is! AssetNotFoundException) {
410 return new TransformerException(info, error, stackTrace);
411 } else {
412 return new MissingInputException(info, error.id);
413 }
414 }
415
417 String toString() => 416 String toString() =>
418 "transform node in $_location for $transformer on $primary"; 417 "transform node in $_location for $transformer on $primary";
419 } 418 }
420 419
421 /// The enum of states that [TransformNode] can be in. 420 /// The enum of states that [TransformNode] can be in.
422 class _TransformNodeState { 421 class _TransformNodeState {
423 /// The transform node is running [Transformer.isPrimary] or 422 /// The transform node is running [Transformer.isPrimary] or
424 /// [Transformer.apply] and doesn't need to re-run them. 423 /// [Transformer.apply] and doesn't need to re-run them.
425 /// 424 ///
426 /// If there are no external changes by the time the processing finishes, this 425 /// If there are no external changes by the time the processing finishes, this
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 /// 478 ///
480 /// Specifically, whether [this] is [APPLIED] or [NOT_PRIMARY]. 479 /// Specifically, whether [this] is [APPLIED] or [NOT_PRIMARY].
481 bool get isDone => isApplied || isNotPrimary; 480 bool get isDone => isApplied || isNotPrimary;
482 481
483 final String name; 482 final String name;
484 483
485 const _TransformNodeState._(this.name); 484 const _TransformNodeState._(this.name);
486 485
487 String toString() => name; 486 String toString() => name;
488 } 487 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/base_transform.dart ('k') | pkg/barback/test/package_graph/errors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698