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

Unified Diff: pkg/barback/lib/src/phase.dart

Issue 22961002: Add more metadata to non-programmatic barback exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/barback/lib/src/phase.dart
diff --git a/pkg/barback/lib/src/phase.dart b/pkg/barback/lib/src/phase.dart
index 025d6525f4e43ec750703a4f683847f70ce39eb4..50c0283475527c17070dde0a8b5d82f918ab80ff 100644
--- a/pkg/barback/lib/src/phase.dart
+++ b/pkg/barback/lib/src/phase.dart
@@ -5,7 +5,6 @@
library barback.phase;
import 'dart:async';
-import 'dart:collection';
import 'asset.dart';
import 'asset_cascade.dart';
@@ -69,14 +68,15 @@ class Phase {
/// being run on an old version of that asset.
var _pendingNewInputs = new Map<AssetId, AssetNode>();
- /// A map of output ids to the asset node outputs for those ids.
+ /// A map of output ids to the asset node outputs for those ids and the
+ /// transforms that produced those asset nodes.
///
/// Usually there's only one node for a given output id. However, it's
/// possible for multiple transformers in this phase to output an asset with
/// the same id. In that case, the chronologically first output emitted is
/// passed forward. We keep track of the other nodes so that if that output is
/// removed, we know which asset to replace it with.
- final _outputs = new Map<AssetId, Queue<AssetNode>>();
+ final _outputs = new Map<AssetId, List<Pair<AssetNode, TransformNode>>>();
Bob Nystrom 2013/08/13 00:04:29 Using a Pair here makes the code pretty hairy. How
nweiz 2013/08/13 19:15:11 Good idea. This will make it easier to do analysis
/// A stream that emits an event whenever this phase becomes dirty and needs
/// to be run.
@@ -319,10 +319,12 @@ class Phase {
return transform.apply().then((outputs) {
for (var output in outputs) {
if (_outputs.containsKey(output.id)) {
- _outputs[output.id].add(output);
+ _outputs[output.id].add(
+ new Pair<AssetNode, TransformNode>(output, transform));
collisions.add(output.id);
} else {
- _outputs[output.id] = new Queue<AssetNode>.from([output]);
+ _outputs[output.id] = new List<Pair<AssetNode, TransformNode>>.from(
+ [new Pair<AssetNode, TransformNode>(output, transform)]);
_next.addInput(output);
}
@@ -336,8 +338,10 @@ class Phase {
for (var collision in collisions) {
// Ensure that there's still a collision. It's possible it was resolved
// while another transform was running.
- if (_outputs[collision].length <= 1) continue;
- cascade.reportError(new AssetCollisionException(collision));
+ if (_outputs[collision].length <= 1) return;
Bob Nystrom 2013/08/13 00:04:29 Shouldn't this still be continue?
nweiz 2013/08/13 19:15:11 Yes, merge error.
+ cascade.reportError(new AssetCollisionException(
+ _outputs[collision].map((pair) => pair.last.info),
+ collision));
}
});
}
@@ -345,31 +349,34 @@ class Phase {
/// Properly resolve collisions when [output] is removed.
void _handleOutputRemoval(AssetNode output) {
output.whenRemoved.then((_) {
- var assets = _outputs[output.id];
- if (assets.length == 1) {
- assert(assets.single == output);
+ var assetsAndTransforms = _outputs[output.id];
+ if (assetsAndTransforms.length == 1) {
+ assert(assetsAndTransforms.single.first == output);
_outputs.remove(output.id);
return;
}
// If there was more than one asset, we're resolving a collision --
// possibly partially.
- var wasFirst = assets.first == output;
- assets.remove(output);
+ var wasFirst = assetsAndTransforms.first.first == output;
+ assetsAndTransforms.removeWhere((pair) => pair.first == output);
// If this was the first asset, we need to pass the next asset
// (chronologically) to the next phase. Pump the event queue first to give
// [_next] a chance to handle the removal of its input before getting a
// new input.
- if (wasFirst) newFuture(() => _next.addInput(assets.first));
+ if (wasFirst) {
+ newFuture(() => _next.addInput(assetsAndTransforms.first.first));
+ }
// If there's still a collision, report it. This lets the user know
// if they've successfully resolved the collision or not.
- if (assets.length > 1) {
+ if (assetsAndTransforms.length > 1) {
// Pump the event queue to ensure that the removal of the input triggers
// a new build to which we can attach the error.
- newFuture(() =>
- cascade.reportError(new AssetCollisionException(output.id)));
+ newFuture(() => cascade.reportError(new AssetCollisionException(
+ assetsAndTransforms.map((pair) => pair.last.info),
+ output.id)));
}
});
}

Powered by Google App Engine
This is Rietveld 408576698