From a48446f94b0119186de0da98c6723c864bb47d03 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Fri, 24 Jul 2020 15:50:01 -0700 Subject: [PATCH] Fix error handling for errors with empty stack traces (#62224) Fixes https://github.com/flutter/flutter/issues/62223 --- .../lib/src/foundation/stack_frame.dart | 1 + .../test/foundation/error_reporting_test.dart | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) 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(); + }); }