diff --git a/packages/flutter/lib/src/foundation/stack_frame.dart b/packages/flutter/lib/src/foundation/stack_frame.dart index c190a3024d..f10d9cf496 100644 --- a/packages/flutter/lib/src/foundation/stack_frame.dart +++ b/packages/flutter/lib/src/foundation/stack_frame.dart @@ -86,6 +86,7 @@ class StackFrame { return stack .trim() .split('\n') + .where((String line) => line.isNotEmpty) .map(fromStackTraceLine) // On the Web in non-debug builds the stack trace includes the exception // message that precedes the stack trace itself. fromStackTraceLine will diff --git a/packages/flutter/test/foundation/error_reporting_test.dart b/packages/flutter/test/foundation/error_reporting_test.dart index 707ac111f5..a2ee99b983 100644 --- a/packages/flutter/test/foundation/error_reporting_test.dart +++ b/packages/flutter/test/foundation/error_reporting_test.dart @@ -201,4 +201,23 @@ Future main() async { console.clear(); FlutterError.resetErrorCount(); }); + + // Regression test for https://github.com/flutter/flutter/issues/62223 + test('Error reporting - empty stack', () async { + expect(console, isEmpty); + FlutterError.dumpErrorToConsole(FlutterErrorDetails( + exception: 'exception - empty stack', + stack: StackTrace.fromString(''), + )); + expect(console.join('\n'), matches( + r'^══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════\n' + r'The following message was thrown:\n' + r'exception - empty stack\n' + r'\n' + r'When the exception was thrown, this was the stack:\n' + r'...\n' + r'════════════════════════════════════════════════════════════════════════════════════════════════════$', + )); + console.clear(); + }); }