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

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

Issue 196223005: Pre-compute the stack chain in Barback's _WrappedException. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.errors; 5 library barback.errors;
6 6
7 import 'package:stack_trace/stack_trace.dart'; 7 import 'package:stack_trace/stack_trace.dart';
8 8
9 import 'asset_id.dart'; 9 import 'asset_id.dart';
10 import 'transformer.dart'; 10 import 'transformer.dart';
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 String toString() => "Transform $transform emitted $id, which wasn't in the " 108 String toString() => "Transform $transform emitted $id, which wasn't in the "
109 "same package (${transform.primaryId.package})."; 109 "same package (${transform.primaryId.package}).";
110 } 110 }
111 111
112 /// Base class for an error that wraps another. 112 /// Base class for an error that wraps another.
113 abstract class _WrappedException implements BarbackException { 113 abstract class _WrappedException implements BarbackException {
114 /// The wrapped exception. 114 /// The wrapped exception.
115 final error; 115 final error;
116 final Chain stackTrace; 116 final Chain stackTrace;
117 117
118 _WrappedException(this.error, StackTrace stackTrace) 118 _WrappedException(error, StackTrace stackTrace)
119 : this.stackTrace = stackTrace == null ? null : 119 : this.error = error,
120 new Chain.forTrace(stackTrace); 120 this.stackTrace = _getChain(error, stackTrace);
121 121
122 String get _message; 122 String get _message;
123 123
124 String toString() { 124 String toString() {
125 var result = "$_message: $error"; 125 var result = "$_message: $error";
126 126 if (stackTrace != null) result = "$result\n${stackTrace.terse}";
127 var stack = stackTrace;
128 if (stack == null && error is Error) stack = error.stackTrace;
129 if (stack != null) {
130 result = "$result\n${stackTrace.terse}";
131 }
132
133 return result; 127 return result;
134 } 128 }
135 } 129 }
136 130
131 /// Returns the stack chain for [error] and [stackTrace].
132 Chain _getChain(error, StackTrace stackTrace) {
133 if (error is Error && stackTrace == null) stackTrace = error.stackTrace;
134 if (stackTrace != null) return new Chain.forTrace(stackTrace);
135 return null;
136 }
137
137 /// Error wrapping an exception thrown by a transform. 138 /// Error wrapping an exception thrown by a transform.
138 class TransformerException extends _WrappedException { 139 class TransformerException extends _WrappedException {
139 /// The transform that threw the exception. 140 /// The transform that threw the exception.
140 final TransformInfo transform; 141 final TransformInfo transform;
141 142
142 TransformerException(this.transform, error, StackTrace stackTrace) 143 TransformerException(this.transform, error, StackTrace stackTrace)
143 : super(error, stackTrace); 144 : super(error, stackTrace);
144 145
145 String get _message => "Transform $transform threw error"; 146 String get _message => "Transform $transform threw error";
146 } 147 }
(...skipping 28 matching lines...) Expand all
175 176
176 bool operator==(other) => 177 bool operator==(other) =>
177 other is TransformInfo && 178 other is TransformInfo &&
178 other.transformer == transformer && 179 other.transformer == transformer &&
179 other.primaryId == primaryId; 180 other.primaryId == primaryId;
180 181
181 int get hashCode => transformer.hashCode ^ primaryId.hashCode; 182 int get hashCode => transformer.hashCode ^ primaryId.hashCode;
182 183
183 String toString() => "$transformer on $primaryId"; 184 String toString() => "$transformer on $primaryId";
184 } 185 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698