| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library barback.build_result; | |
| 6 | |
| 7 import 'errors.dart'; | |
| 8 import 'utils.dart'; | |
| 9 | |
| 10 /// An event indicating that the cascade has finished building all assets. | |
| 11 /// | |
| 12 /// A build can end either in success or failure. If there were no errors during | |
| 13 /// the build, it's considered to be a success; any errors render it a failure, | |
| 14 /// although individual assets may still have built successfully. | |
| 15 class BuildResult { | |
| 16 // TODO(rnystrom): Revise how to track error results. Errors can come from | |
| 17 // both logs and exceptions. Accumulating them is likely slow and a waste of | |
| 18 // memory. If we do want to accumulate them, we should at least unify them | |
| 19 // in a single collection (probably of log entries). | |
| 20 /// All errors that were thrown during the build. | |
| 21 final Set<BarbackException> errors; | |
| 22 | |
| 23 /// `true` if the build succeeded. | |
| 24 bool get succeeded => errors.isEmpty; | |
| 25 | |
| 26 BuildResult(Iterable<BarbackException> errors) | |
| 27 : errors = flattenAggregateExceptions(errors).toSet(); | |
| 28 | |
| 29 /// Creates a build result indicating a successful build. | |
| 30 /// | |
| 31 /// This equivalent to a build result with no errors. | |
| 32 BuildResult.success() | |
| 33 : this([]); | |
| 34 | |
| 35 /// Creates a single [BuildResult] that contains all of the errors of | |
| 36 /// [results]. | |
| 37 factory BuildResult.aggregate(Iterable<BuildResult> results) { | |
| 38 var errors = unionAll(results.map((result) => result.errors)); | |
| 39 return new BuildResult(errors); | |
| 40 } | |
| 41 | |
| 42 String toString() { | |
| 43 if (succeeded) return "success"; | |
| 44 | |
| 45 return "errors:\n" + errors.map((error) { | |
| 46 var stackTrace = null; | |
| 47 if (error is TransformerException || error is AssetLoadException) { | |
| 48 stackTrace = error.stackTrace.terse; | |
| 49 } | |
| 50 | |
| 51 var msg = new StringBuffer(); | |
| 52 msg.write(prefixLines(error.toString())); | |
| 53 if (stackTrace != null) { | |
| 54 msg.write("\n\n"); | |
| 55 msg.write("Stack chain:\n"); | |
| 56 msg.write(prefixLines(stackTrace.toString())); | |
| 57 } | |
| 58 return msg.toString(); | |
| 59 }).join("\n\n"); | |
| 60 } | |
| 61 } | |
| OLD | NEW |