| OLD | NEW |
| 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 '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 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 InvalidOutputException(this.transform, this.id); | 108 InvalidOutputException(this.transform, this.id); |
| 109 | 109 |
| 110 String toString() => "Transform $transform emitted $id, which wasn't in the " | 110 String toString() => "Transform $transform emitted $id, which wasn't in the " |
| 111 "same package (${transform.primaryId.package})."; | 111 "same package (${transform.primaryId.package})."; |
| 112 } | 112 } |
| 113 | 113 |
| 114 /// Base class for an error that wraps another. | 114 /// Base class for an error that wraps another. |
| 115 abstract class _WrappedException implements BarbackException { | 115 abstract class _WrappedException implements BarbackException { |
| 116 /// The wrapped exception. | 116 /// The wrapped exception. |
| 117 final error; | 117 final error; |
| 118 final StackTrace stackTrace; |
| 118 | 119 |
| 119 _WrappedException(this.error); | 120 _WrappedException(this.error, this.stackTrace); |
| 120 | 121 |
| 121 String get _message; | 122 String get _message; |
| 122 | 123 |
| 123 String toString() { | 124 String toString() { |
| 124 var result = "$_message: $error"; | 125 var result = "$_message: $error"; |
| 125 | 126 |
| 126 var stack = getAttachedStackTrace(error); | 127 var stack = stackTrace; |
| 128 if (stack == null && error is Error) stack = error.stackTrace; |
| 127 if (stack != null) { | 129 if (stack != null) { |
| 128 result = "$result\n${new Trace.from(stack).terse}"; | 130 result = "$result\n${new Trace.from(stack).terse}"; |
| 129 } | 131 } |
| 130 | 132 |
| 131 return result; | 133 return result; |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 | 136 |
| 135 /// Error wrapping an exception thrown by a transform. | 137 /// Error wrapping an exception thrown by a transform. |
| 136 class TransformerException extends _WrappedException { | 138 class TransformerException extends _WrappedException { |
| 137 /// The transform that threw the exception. | 139 /// The transform that threw the exception. |
| 138 final TransformInfo transform; | 140 final TransformInfo transform; |
| 139 | 141 |
| 140 TransformerException(this.transform, error) | 142 TransformerException(this.transform, error, StackTrace stackTrace) |
| 141 : super(error); | 143 : super(error, stackTrace); |
| 142 | 144 |
| 143 String get _message => "Transform $transform threw error"; | 145 String get _message => "Transform $transform threw error"; |
| 144 } | 146 } |
| 145 | 147 |
| 146 /// Error thrown when a source asset [id] fails to load. | 148 /// Error thrown when a source asset [id] fails to load. |
| 147 /// | 149 /// |
| 148 /// This can be thrown either because the source asset was expected to exist and | 150 /// This can be thrown either because the source asset was expected to exist and |
| 149 /// did not or because reading it failed somehow. | 151 /// did not or because reading it failed somehow. |
| 150 class AssetLoadException extends _WrappedException { | 152 class AssetLoadException extends _WrappedException { |
| 151 final AssetId id; | 153 final AssetId id; |
| 152 | 154 |
| 153 AssetLoadException(this.id, error) | 155 AssetLoadException(this.id, error, [StackTrace stackTrace]) |
| 154 : super(error); | 156 : super(error, stackTrace); |
| 155 | 157 |
| 156 String get _message => "Failed to load source asset $id"; | 158 String get _message => "Failed to load source asset $id"; |
| 157 } | 159 } |
| 158 | 160 |
| 159 /// Information about a single transform in the barback graph. | 161 /// Information about a single transform in the barback graph. |
| 160 /// | 162 /// |
| 161 /// Identifies a single transformation in the barback graph. | 163 /// Identifies a single transformation in the barback graph. |
| 162 /// | 164 /// |
| 163 /// A transformation is uniquely identified by the ID of its primary input, and | 165 /// A transformation is uniquely identified by the ID of its primary input, and |
| 164 /// the transformer that is applied to it. | 166 /// the transformer that is applied to it. |
| 165 class TransformInfo { | 167 class TransformInfo { |
| 166 /// The transformer that's run for this transform. | 168 /// The transformer that's run for this transform. |
| 167 final Transformer transformer; | 169 final Transformer transformer; |
| 168 | 170 |
| 169 /// The id of this transform's primary asset. | 171 /// The id of this transform's primary asset. |
| 170 final AssetId primaryId; | 172 final AssetId primaryId; |
| 171 | 173 |
| 172 TransformInfo(this.transformer, this.primaryId); | 174 TransformInfo(this.transformer, this.primaryId); |
| 173 | 175 |
| 174 bool operator==(other) => | 176 bool operator==(other) => |
| 175 other is TransformInfo && | 177 other is TransformInfo && |
| 176 other.transformer == transformer && | 178 other.transformer == transformer && |
| 177 other.primaryId == primaryId; | 179 other.primaryId == primaryId; |
| 178 | 180 |
| 179 int get hashCode => transformer.hashCode ^ primaryId.hashCode; | 181 int get hashCode => transformer.hashCode ^ primaryId.hashCode; |
| 180 | 182 |
| 181 String toString() => "$transformer on $primaryId"; | 183 String toString() => "$transformer on $primaryId"; |
| 182 } | 184 } |
| OLD | NEW |