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

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: 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
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..8e624da7cefbd458788a78a5e7246d90f74a244e 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,92 @@ 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.";
}
/// 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.id);
+ MissingInputException(this.transform, this.id);
String toString() => "Missing input $id.";
}
/// Error thrown when a transformer outputs an asset with the wrong package
/// 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.
-class InvalidOutputException implements Exception {
- final String package;
+class InvalidOutputException implements BarbackException {
+ /// The transform that output the asset.
+ final TransformInfo transform;
+ final AssetId id;
+
+ InvalidOutputException(this.transform, this.id);
+
+ String toString() => "Invalid output $id: must be in package "
+ "${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
+}
+
+/// Error wrapping an exception thrown by a transform.
+class TransformerException implements BarbackException {
+ /// The transform that threw the exception.
+ final TransformInfo transform;
+
+ /// The wrapped exception.
+ final error;
+
+ TransformerException(this.transform, this.error);
+}
+
+/// 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.
+///
+/// A transform is a [transformer] as it's run on a single asset, its
+/// [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.
+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;
- String toString() => "Invalid output $id: must be in package $package.";
+ int get hashCode => transformer.hashCode ^ primaryId.hashCode;
}

Powered by Google App Engine
This is Rietveld 408576698