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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/errors.dart
diff --git a/pkg/barback/lib/src/errors.dart b/pkg/barback/lib/src/errors.dart
index 9ebca8e608ab57273230922ffd5d3fe3334d64d3..a379ae516f41217a23475e2ee8123c7ffb0f7aa6 100644
--- a/pkg/barback/lib/src/errors.dart
+++ b/pkg/barback/lib/src/errors.dart
@@ -7,7 +7,10 @@ library barback.errors;
import 'dart:async';
import 'dart:io';
+import 'package:stack_trace/stack_trace.dart';
+
import 'asset_id.dart';
+import 'transformer.dart';
/// Error thrown when an asset with [id] cannot be found.
class AssetNotFoundException implements Exception {
@@ -18,32 +21,99 @@ class AssetNotFoundException implements Exception {
String toString() => "Could not find asset $id.";
}
-/// Error thrown when two transformers both output an asset with [id].
-class AssetCollisionException implements Exception {
+/// The interface for exceptions from the barback graph or its transformers.
+///
+/// These exceptions are never produced by programming errors in barback.
+abstract class BarbackException implements Exception {}
+
+/// Error thrown when two or more transformers both output an asset with [id].
+class AssetCollisionException implements BarbackException {
+ /// All the transforms that output an asset with [id].
+ final Set<TransformInfo> transforms;
final AssetId id;
- AssetCollisionException(this.id);
+ AssetCollisionException(Iterable<TransformInfo> transforms, this.id)
+ : transforms = new Set.from(transforms);
- String toString() => "Got collision on asset $id.";
+ String toString() => "Transforms $transforms all emitted asset $id.";
}
/// Error thrown when a transformer requests an input [id] which cannot be
/// found.
-class MissingInputException implements Exception {
+class MissingInputException implements BarbackException {
+ /// The transform that requested [id].
+ final TransformInfo transform;
+ final AssetId id;
+
+ MissingInputException(this.transform, this.id);
+
+ String toString() => "Transform $transform tried to load missing input $id.";
+}
+
+/// Error thrown when a transformer outputs an asset to a different package than
+/// the primary input's.
+class InvalidOutputException implements BarbackException {
+ /// The transform that output the asset.
+ final TransformInfo transform;
final AssetId id;
- MissingInputException(this.id);
+ InvalidOutputException(this.transform, this.id);
+
+ String toString() => "Transform $transform emitted $id, which wasn't in the "
+ "same package (${transform.primaryId.package}).";
+}
+
+/// Error wrapping an exception thrown by a transform.
+class TransformerException implements BarbackException {
+ /// The transform that threw the exception.
+ final TransformInfo transform;
- String toString() => "Missing input $id.";
+ /// The wrapped exception.
+ final error;
+
+ TransformerException(this.transform, this.error);
+
+ String toString() => "Transform $transform threw error: $error\n" +
+ new Trace.from(getAttachedStackTrace(error)).terse.toString();
}
-/// Error thrown when a transformer outputs an asset with the wrong package
-/// name.
-class InvalidOutputException implements Exception {
- final String package;
+/// Error thrown when a source asset [id] fails to load.
+///
+/// This can be thrown either because the source asset was expected to exist and
+/// did not or because reading it failed somehow.
+class AssetLoadException implements BarbackException {
final AssetId id;
- InvalidOutputException(this.package, this.id);
+ /// The wrapped exception.
+ final error;
+
+ AssetLoadException(this.id, this.error);
+
+ String toString() => "Failed to load source asset $id: $error\n"
+ "${new Trace.from(getAttachedStackTrace(error)).terse}";
+}
+
+/// Information about a single transform in the barback graph.
+///
+/// Identifies a single transformation in the barback graph.
+///
+/// A transformation is uniquely identified by the ID of its primary input, and
+/// the transformer that is applied to it.
+class TransformInfo {
+ /// The transformer that's run for this transform.
+ final Transformer transformer;
+
+ /// The id of this transform's primary asset.
+ final AssetId primaryId;
+
+ TransformInfo(this.transformer, this.primaryId);
+
+ bool operator==(other) =>
+ other is TransformInfo &&
+ other.transformer == transformer &&
+ other.primaryId == primaryId;
+
+ int get hashCode => transformer.hashCode ^ primaryId.hashCode;
- String toString() => "Invalid output $id: must be in package $package.";
+ String toString() => "$transformer on $primaryId";
}
« 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