Index: pkg/barback/lib/src/serialize.dart |
diff --git a/pkg/barback/lib/src/serialize.dart b/pkg/barback/lib/src/serialize.dart |
index f0b356eca3b3657092167eeb86d4f5f5c4eedcf1..7114039e44d5cc417baf8dfc62a97400619447c3 100644 |
--- a/pkg/barback/lib/src/serialize.dart |
+++ b/pkg/barback/lib/src/serialize.dart |
@@ -114,19 +114,13 @@ 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, ''); |