Chromium Code Reviews| 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 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:stack_trace/stack_trace.dart'; | |
| 11 | |
| 10 import 'asset_id.dart'; | 12 import 'asset_id.dart'; |
| 13 import 'transformer.dart'; | |
| 11 | 14 |
| 12 /// Error thrown when an asset with [id] cannot be found. | 15 /// Error thrown when an asset with [id] cannot be found. |
| 13 class AssetNotFoundException implements Exception { | 16 class AssetNotFoundException implements Exception { |
| 14 final AssetId id; | 17 final AssetId id; |
| 15 | 18 |
| 16 AssetNotFoundException(this.id); | 19 AssetNotFoundException(this.id); |
| 17 | 20 |
| 18 String toString() => "Could not find asset $id."; | 21 String toString() => "Could not find asset $id."; |
| 19 } | 22 } |
| 20 | 23 |
| 21 /// Error thrown when two transformers both output an asset with [id]. | 24 /// The interface for exceptions from the barback graph or its transformers. |
| 22 class AssetCollisionException implements Exception { | 25 /// |
| 26 /// These exceptions are never produced by programming errors in barback. | |
| 27 abstract class BarbackException implements Exception {} | |
| 28 | |
| 29 /// Error thrown when two or more transformers both output an asset with [id]. | |
| 30 class AssetCollisionException implements BarbackException { | |
| 31 /// All the transforms that output an asset with [id]. | |
| 32 final Set<TransformInfo> transforms; | |
| 23 final AssetId id; | 33 final AssetId id; |
| 24 | 34 |
| 25 AssetCollisionException(this.id); | 35 AssetCollisionException(Iterable<TransformInfo> transforms, this.id) |
| 36 : transforms = new Set.from(transforms); | |
| 26 | 37 |
| 27 String toString() => "Got collision on asset $id."; | 38 String toString() => "Got collision on asset $id."; |
| 28 } | 39 } |
| 29 | 40 |
| 30 /// Error thrown when a transformer requests an input [id] which cannot be | 41 /// Error thrown when a transformer requests an input [id] which cannot be |
| 31 /// found. | 42 /// found. |
| 32 class MissingInputException implements Exception { | 43 class MissingInputException implements BarbackException { |
| 44 /// The transform that requested [id]. | |
| 45 final TransformInfo transform; | |
| 33 final AssetId id; | 46 final AssetId id; |
| 34 | 47 |
| 35 MissingInputException(this.id); | 48 MissingInputException(this.transform, this.id); |
| 36 | 49 |
| 37 String toString() => "Missing input $id."; | 50 String toString() => "Missing input $id."; |
| 38 } | 51 } |
| 39 | 52 |
| 40 /// Error thrown when a transformer outputs an asset with the wrong package | 53 /// Error thrown when a transformer outputs an asset with the wrong package |
| 41 /// name. | 54 /// name. |
|
Bob Nystrom
2013/08/13 00:04:29
"with the wrong..." -> "to a different package tha
nweiz
2013/08/13 19:15:11
Done.
| |
| 42 class InvalidOutputException implements Exception { | 55 class InvalidOutputException implements BarbackException { |
| 43 final String package; | 56 /// The transform that output the asset. |
| 57 final TransformInfo transform; | |
| 44 final AssetId id; | 58 final AssetId id; |
| 45 | 59 |
| 46 InvalidOutputException(this.package, this.id); | 60 InvalidOutputException(this.transform, this.id); |
| 47 | 61 |
| 48 String toString() => "Invalid output $id: must be in package $package."; | 62 String toString() => "Invalid output $id: must be in package " |
| 63 "${transform.primaryId.package}."; | |
|
Bob Nystrom
2013/08/13 00:04:29
Can you explain in the error message *why* it must
nweiz
2013/08/13 19:15:11
I've added data about the transforms to all the er
| |
| 49 } | 64 } |
| 65 | |
| 66 /// Error wrapping an exception thrown by a transform. | |
| 67 class TransformerException implements BarbackException { | |
| 68 /// The transform that threw the exception. | |
| 69 final TransformInfo transform; | |
| 70 | |
| 71 /// The wrapped exception. | |
| 72 final error; | |
| 73 | |
| 74 TransformerException(this.transform, this.error); | |
| 75 } | |
| 76 | |
| 77 /// Error thrown when a source asset [id] fails to load. | |
| 78 /// | |
| 79 /// This can be thrown either because the source asset was expected to exist and | |
| 80 /// did not or because reading it failed somehow. | |
| 81 class AssetLoadException implements BarbackException { | |
| 82 final AssetId id; | |
| 83 | |
| 84 /// The wrapped exception. | |
| 85 final error; | |
| 86 | |
| 87 AssetLoadException(this.id, this.error); | |
| 88 | |
| 89 String toString() => "Failed to load source asset $id: $error\n" | |
| 90 "${new Trace.from(getAttachedStackTrace(error)).terse}"; | |
| 91 } | |
| 92 | |
| 93 /// Information about a single transform in the barback graph. | |
| 94 /// | |
| 95 /// A transform is a [transformer] as it's run on a single asset, its | |
| 96 /// [primaryId]. | |
|
Bob Nystrom
2013/08/13 00:04:29
This is worded a bit strangely. How about:
Identi
nweiz
2013/08/13 19:15:11
Done.
| |
| 97 class TransformInfo { | |
| 98 /// The transformer that's run for this transform. | |
| 99 final Transformer transformer; | |
| 100 | |
| 101 /// The id of this transform's primary asset. | |
| 102 final AssetId primaryId; | |
| 103 | |
| 104 TransformInfo(this.transformer, this.primaryId); | |
| 105 | |
| 106 bool operator==(other) => | |
| 107 other is TransformInfo && | |
| 108 other.transformer == transformer && | |
| 109 other.primaryId == primaryId; | |
| 110 | |
| 111 int get hashCode => transformer.hashCode ^ primaryId.hashCode; | |
| 112 } | |
| OLD | NEW |