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

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

Issue 22961002: Add more metadata to non-programmatic barback exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Small fix Created 7 years, 4 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 | « pkg/barback/lib/src/build_result.dart ('k') | pkg/barback/lib/src/package_graph.dart » ('j') | 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 '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() => "Transforms $transforms all emitted 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() => "Transform $transform tried to load 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 to a different package than
41 /// name. 54 /// the primary input's.
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() => "Transform $transform emitted $id, which wasn't in the "
63 "same package (${transform.primaryId.package}).";
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 String toString() => "Transform $transform threw error: $error\n" +
77 new Trace.from(getAttachedStackTrace(error)).terse.toString();
78 }
79
80 /// Error thrown when a source asset [id] fails to load.
81 ///
82 /// This can be thrown either because the source asset was expected to exist and
83 /// did not or because reading it failed somehow.
84 class AssetLoadException implements BarbackException {
85 final AssetId id;
86
87 /// The wrapped exception.
88 final error;
89
90 AssetLoadException(this.id, this.error);
91
92 String toString() => "Failed to load source asset $id: $error\n"
93 "${new Trace.from(getAttachedStackTrace(error)).terse}";
94 }
95
96 /// Information about a single transform in the barback graph.
97 ///
98 /// Identifies a single transformation in the barback graph.
99 ///
100 /// A transformation is uniquely identified by the ID of its primary input, and
101 /// the transformer that is applied to it.
102 class TransformInfo {
103 /// The transformer that's run for this transform.
104 final Transformer transformer;
105
106 /// The id of this transform's primary asset.
107 final AssetId primaryId;
108
109 TransformInfo(this.transformer, this.primaryId);
110
111 bool operator==(other) =>
112 other is TransformInfo &&
113 other.transformer == transformer &&
114 other.primaryId == primaryId;
115
116 int get hashCode => transformer.hashCode ^ primaryId.hashCode;
117
118 String toString() => "$transformer on $primaryId";
119 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/build_result.dart ('k') | pkg/barback/lib/src/package_graph.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698