Chromium Code Reviews| Index: pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart |
| diff --git a/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart b/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart |
| index 1dbb7a4b322dfa4c6ce6487b5ea5cb4c41dea513..4809ee0944785ad26eec4dd8bd3ad2c7f32b12ff 100644 |
| --- a/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart |
| +++ b/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart |
| @@ -43,8 +43,15 @@ class DirectoryDescriptor extends Descriptor { |
| throw "Directory not found: '$fullPath'."; |
| } |
| - return Future.wait( |
| - contents.map((entry) => entry.validateNow(fullPath)).toList()); |
| + return Future.wait(contents.map((entry) { |
| + return new Future.of(() => entry.validateNow(fullPath)) |
| + .then((_) => null) |
| + .catchError((e) => e.error); |
| + })).then((results) { |
| + var errors = results.where((e) => e != null); |
| + if (errors.isEmpty) return; |
| + throw _DirectoryValidationError.merge(errors); |
| + }); |
| } |
| Stream<List<int>> load(String pathToLoad) { |
| @@ -96,3 +103,24 @@ class DirectoryDescriptor extends Descriptor { |
| return buffer.toString(); |
| } |
| } |
| + |
| +/// A class for formatting errors thrown by [DirectoryDescriptor]. |
| +class _DirectoryValidationError { |
| + final Collection<String> errors; |
|
Bob Nystrom
2013/03/19 20:56:13
List?
nweiz
2013/03/19 21:03:33
Why? We don't rely on any List-specific methods he
|
| + |
| + static _DirectoryValidationError merge(Iterable errors) { |
|
Bob Nystrom
2013/03/19 20:56:13
How about a comment here like:
Flatten out nested
nweiz
2013/03/19 21:03:33
Done.
|
| + return new _DirectoryValidationError(errors.expand((error) { |
| + if (error is _DirectoryValidationError) return error.errors; |
| + return [error]; |
| + })); |
| + } |
| + |
| + _DirectoryValidationError(Iterable errors) |
| + : errors = errors.map((e) => e.toString()).toList(); |
| + |
| + String toString() { |
| + if (errors.length == 1) return errors.single; |
| + return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) |
| + .join('\n'); |
| + } |
| +} |