Commit b5e471ee authored by Ian Hickson's avatar Ian Hickson

Include the error runtimeType in the message. (#3355)

Fixes https://github.com/flutter/flutter/issues/3352
parent d348f28d
...@@ -20,6 +20,10 @@ class FlutterErrorDetails { ...@@ -20,6 +20,10 @@ class FlutterErrorDetails {
/// ///
/// The framework calls this constructor when catching an exception that will /// The framework calls this constructor when catching an exception that will
/// subsequently be reported using [FlutterError.onError]. /// subsequently be reported using [FlutterError.onError].
///
/// The [exception] must not be null; other arguments can be left to
/// their default values. (`throw null` results in a
/// [NullThrownError] exception.)
const FlutterErrorDetails({ const FlutterErrorDetails({
this.exception, this.exception,
this.stack, this.stack,
...@@ -150,8 +154,25 @@ class FlutterError extends AssertionError { ...@@ -150,8 +154,25 @@ class FlutterError extends AssertionError {
final String header = '\u2550\u2550\u2561 EXCEPTION CAUGHT BY ${details.library} \u255E'.toUpperCase(); final String header = '\u2550\u2550\u2561 EXCEPTION CAUGHT BY ${details.library} \u255E'.toUpperCase();
final String footer = '\u2501' * _kWrapWidth; final String footer = '\u2501' * _kWrapWidth;
debugPrint('$header${"\u2550" * (footer.length - header.length)}'); debugPrint('$header${"\u2550" * (footer.length - header.length)}');
debugPrint('The following exception was raised${ details.context != null ? " ${details.context}" : ""}:', wrapWidth: _kWrapWidth); final String verb = 'thrown${ details.context != null ? " ${details.context}" : ""}';
if (details.exception is NullThrownError) {
debugPrint('The null value was $verb.', wrapWidth: _kWrapWidth);
} else if (details.exception is num) {
debugPrint('The number ${details.exception} was $verb.', wrapWidth: _kWrapWidth);
} else {
String errorName;
if (details.exception is AssertionError) {
errorName = 'assertion';
} else if (details.exception is String) {
errorName = 'message';
} else if (details.exception is Error || details.exception is Exception) {
errorName = '${details.exception.runtimeType}';
} else {
errorName = '${details.exception.runtimeType} object';
}
debugPrint('The following $errorName was $verb:', wrapWidth: _kWrapWidth);
debugPrint('${details.exception}', wrapWidth: _kWrapWidth); debugPrint('${details.exception}', wrapWidth: _kWrapWidth);
}
if ((details.exception is AssertionError) && (details.exception is! FlutterError)) { if ((details.exception is AssertionError) && (details.exception is! FlutterError)) {
debugPrint('Either the assertion indicates an error in the framework itself, or we should ' debugPrint('Either the assertion indicates an error in the framework itself, or we should '
'provide substantially more information in this error message to help you determine ' 'provide substantially more information in this error message to help you determine '
...@@ -171,7 +192,7 @@ class FlutterError extends AssertionError { ...@@ -171,7 +192,7 @@ class FlutterError extends AssertionError {
debugPrint(footer); debugPrint(footer);
} }
} else { } else {
debugPrint('Another exception was raised: ${details.exception.toString().split("\n")[0]}'); debugPrint('Another exception was thrown: ${details.exception.toString().split("\n")[0]}');
} }
_errorCount += 1; _errorCount += 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment