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

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart

Issue 140973006: Update [getErrorMessage] to avoid throwing away useful information. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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/pubspec.yaml ('k') | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
index 0f59bf93d350a443ffc7ae21021ed835bab0d652..36790001ab30116c63e2acdb03d15ff79e3a4497 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
@@ -316,22 +316,16 @@ class CrossIsolateException implements Exception {
String toString() => "\$message\\n\$stackTrace";
}
-// Get a string description of an exception.
-//
-// Most exception types have a "message" property. We prefer this since
-// it skips the "Exception:", "HttpException:", etc. prefix that calling
-// toString() adds. But, alas, "message" isn't actually defined in the
-// base Exception type so there's no easy way to know if it's available
-// short of a giant pile of type tests for each known exception type.
-//
-// So just try it. If it throws, default to toString().
-String getErrorMessage(error) {
- try {
- return error.message;
- } on NoSuchMethodError catch (_) {
- return error.toString();
- }
-}
+/// A regular expression to match the exception prefix that some exceptions'
+/// [Object.toString] values contain.
+final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): ');
+
+/// Get a string description of an exception.
+///
+/// Many exceptions include the exception class name at the beginning of their
+/// [toString], so we remove that if it exists.
+String getErrorMessage(error) =>
+ error.toString().replaceFirst(_exceptionPrefix, '');
/// Returns a buffered stream that will emit the same values as the stream
/// returned by [future] once [future] completes. If [future] completes to an
« no previous file with comments | « pkg/barback/pubspec.yaml ('k') | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698