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

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

Issue 26572010: Improve barback/pub logging. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing file. Created 7 years, 2 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.build_result; 5 library barback.build_result;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:stack_trace/stack_trace.dart'; 9 import 'package:stack_trace/stack_trace.dart';
10 10
11 import 'barback_logger.dart';
11 import 'errors.dart'; 12 import 'errors.dart';
12 import 'utils.dart'; 13 import 'utils.dart';
13 14
14 /// An event indicating that the cascade has finished building all assets. 15 /// An event indicating that the cascade has finished building all assets.
15 /// 16 ///
16 /// A build can end either in success or failure. If there were no errors during 17 /// A build can end either in success or failure. If there were no errors during
17 /// the build, it's considered to be a success; any errors render it a failure, 18 /// the build, it's considered to be a success; any errors render it a failure,
18 /// although individual assets may still have built successfully. 19 /// although individual assets may still have built successfully.
19 class BuildResult { 20 class BuildResult {
20 /// All errors that occurred during the build. 21 // TODO(rnystrom): Revise how to track error results. Errors can come from
22 // both logs and exceptions. Accumulating them is likely slow and a waste of
23 // memory. If we do want to accumulate them, we should at least unify them
24 // in a single collection (probably of log entries).
25 /// All errors that were thrown during the build.
21 final Set<BarbackException> errors; 26 final Set<BarbackException> errors;
22 27
28 /// The number of error log entries that occurred during this build.
29 final int _numErrorLogs;
30
23 /// `true` if the build succeeded. 31 /// `true` if the build succeeded.
24 bool get succeeded => errors.isEmpty; 32 bool get succeeded => errors.isEmpty && _numErrorLogs == 0;
25 33
26 BuildResult(Iterable<BarbackException> errors) 34 /// Gets the number of error exceptions and log entries.
35 int get numErrors => errors.length + _numErrorLogs;
36
37 BuildResult(Iterable<BarbackException> errors, this._numErrorLogs)
27 : errors = flattenAggregateExceptions(errors).toSet(); 38 : errors = flattenAggregateExceptions(errors).toSet();
28 39
29 /// Creates a build result indicating a successful build. 40 /// Creates a build result indicating a successful build.
30 /// 41 ///
31 /// This equivalent to a build result with no errors. 42 /// This equivalent to a build result with no errors.
32 BuildResult.success() 43 BuildResult.success()
33 : this([]); 44 : this([], 0);
34 45
35 String toString() { 46 String toString() {
36 if (succeeded) return "success"; 47 if (succeeded) return "success";
37 48
38 return "errors:\n" + errors.map((error) { 49 return "errors:\n" + errors.map((error) {
39 var stackTrace = getAttachedStackTrace(error); 50 var stackTrace = getAttachedStackTrace(error);
40 if (stackTrace != null) stackTrace = new Trace.from(stackTrace); 51 if (stackTrace != null) stackTrace = new Trace.from(stackTrace);
41 52
42 var msg = new StringBuffer(); 53 var msg = new StringBuffer();
43 msg.write(prefixLines(error.toString())); 54 msg.write(prefixLines(error.toString()));
44 if (stackTrace != null) { 55 if (stackTrace != null) {
45 msg.write("\n\n"); 56 msg.write("\n\n");
46 msg.write("Stack trace:\n"); 57 msg.write("Stack trace:\n");
47 msg.write(prefixLines(stackTrace.toString())); 58 msg.write(prefixLines(stackTrace.toString()));
48 } 59 }
49 return msg.toString(); 60 return msg.toString();
50 }).join("\n\n"); 61 }).join("\n\n");
51 } 62 }
52 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698