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

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

Issue 22824023: Start sketching out a buildAll() method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't wrap a single error in an aggregate. 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/errors.dart
diff --git a/pkg/barback/lib/src/errors.dart b/pkg/barback/lib/src/errors.dart
index 138984ce58200de5d450f9a1b108efcb68f60b64..13886978505f46b51384d6f9853ea2a5600bdb23 100644
--- a/pkg/barback/lib/src/errors.dart
+++ b/pkg/barback/lib/src/errors.dart
@@ -20,11 +20,32 @@ class AssetNotFoundException implements Exception {
String toString() => "Could not find asset $id.";
}
+/// Recursively removes any occurrences of [AggregateException] in [errors]
nweiz 2013/08/20 19:59:26 "removes" -> "replaces" Doing this recursively se
Bob Nystrom 2013/08/20 21:29:20 Done.
+/// with the list of errors it contains.
+Iterable<BarbackException> flattenAggregateExceptions(
+ Iterable<BarbackException> errors) {
+ return errors.expand((error) {
+ if (error is! AggregateException) return [error];
+ return flattenAggregateExceptions(error.errors);
+ });
+}
+
/// The interface for exceptions from the barback graph or its transformers.
///
/// These exceptions are never produced by programming errors in barback.
abstract class BarbackException implements Exception {}
+/// An error that wraps a collection of other [BarbackException]s.
+///
+/// It implicitly flattens any [AggregateException]s that occur in the list
nweiz 2013/08/20 19:59:26 "list exceptions" -> "list of exceptions"
Bob Nystrom 2013/08/20 21:29:20 Done.
+/// exceptions it wraps.
+class AggregateException implements BarbackException {
+ final List<BarbackException> errors;
nweiz 2013/08/20 19:59:26 It seems like this should be a set, since the orde
Bob Nystrom 2013/08/20 21:29:20 Done.
+
+ AggregateException(Iterable<BarbackException> errors)
+ : errors = flattenAggregateExceptions(errors).toList();
+}
nweiz 2013/08/20 19:59:26 It would be nice to have a static method here that
Bob Nystrom 2013/08/20 21:29:20 Done.
+
/// Error thrown when two or more transformers both output an asset with [id].
class AssetCollisionException implements BarbackException {
/// All the transforms that output an asset with [id].

Powered by Google App Engine
This is Rietveld 408576698