From f33e88cef7f8cd533cdf91c0f197015b0a139f90 Mon Sep 17 00:00:00 2001 From: Andre Date: Fri, 21 May 2021 13:53:50 -0400 Subject: [PATCH] Prevent DiagnosticsStackTrace truncation (#82140) --- .../lib/src/foundation/assertions.dart | 3 ++ .../test/foundation/error_reporting_test.dart | 43 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index 44af2b78b9..dccee7caf0 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -1218,6 +1218,9 @@ class DiagnosticsStackTrace extends DiagnosticsBlock { static DiagnosticsNode _createStackFrame(String frame) { return DiagnosticsNode.message(frame, allowWrap: false); } + + @override + bool get allowTruncate => false; } class _FlutterErrorDetailsNode extends DiagnosticableNode { diff --git a/packages/flutter/test/foundation/error_reporting_test.dart b/packages/flutter/test/foundation/error_reporting_test.dart index 3a9488c868..140938a73b 100644 --- a/packages/flutter/test/foundation/error_reporting_test.dart +++ b/packages/flutter/test/foundation/error_reporting_test.dart @@ -213,10 +213,49 @@ Future main() async { 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'When the exception was thrown, this was the stack\n' r'════════════════════════════════════════════════════════════════════════════════════════════════════$', )); console.clear(); + FlutterError.resetErrorCount(); + }); + + test('Stack traces are not truncated', () async { + const String stackString = ''' +#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39) +#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:38:5) +#2 new Text (package:flutter/src/widgets/text.dart:287:10) +#3 _MyHomePageState.build (package:hello_flutter/main.dart:72:16) +#4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4414:27) +#5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4303:15) +#6 Element.rebuild (package:flutter/src/widgets/framework.dart:4027:5) +#7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4286:5) +#8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4461:11) +#9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4281:5) +#10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3276:14)'''; + + expect(console, isEmpty); + FlutterError.dumpErrorToConsole(FlutterErrorDetails( + exception: AssertionError('Test assertion'), + stack: StackTrace.fromString(stackString), + )); + final String x = console.join('\n'); + expect(x, startsWith(''' +══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════ +The following assertion was thrown: +Assertion failed: "Test assertion" + +When the exception was thrown, this was the stack: +#2 new Text (package:flutter/src/widgets/text.dart:287:10) +#3 _MyHomePageState.build (package:hello_flutter/main.dart:72:16) +#4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4414:27) +#5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4303:15) +#6 Element.rebuild (package:flutter/src/widgets/framework.dart:4027:5) +#7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4286:5) +#8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4461:11) +#9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4281:5)''', + )); + console.clear(); + FlutterError.resetErrorCount(); }); }