From a2cd401a8fd51ba4b48a7c070a21a1eac5cffa20 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 9 Nov 2022 10:25:06 -0800 Subject: [PATCH 1/5] Include entire description up to stack trace --- dwds/lib/src/debugging/inspector.dart | 18 ++++++++++-- dwds/test/inspector_test.dart | 40 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index 3b1e22bbc..63cb258b7 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file.import 'dart:async'; +import 'dart:math'; + import 'package:async/async.dart'; import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; @@ -83,6 +85,9 @@ class AppInspector implements AppInspectorInterface { /// Regex used to extract the message from an exception description. static final exceptionMessageRegex = RegExp(r'^.*$', multiLine: true); + /// Regex used to extract a stack trace line from the exception description. + static final stackTraceLineRegex = RegExp(r'^\s*at\s.*$', multiLine: true); + AppInspector._( this._appConnection, this._isolate, @@ -611,8 +616,17 @@ class AppInspector implements AppInspectorInterface { if (mappedStack == null || mappedStack.isEmpty) { return description; } - var message = exceptionMessageRegex.firstMatch(description)?.group(0); - message = (message != null) ? '$message\n' : ''; + final message = _allLinesBeforeStackTrace(description); return '$message$mappedStack'; } + + String _allLinesBeforeStackTrace(String description) { + var message = ''; + for (final match in exceptionMessageRegex.allMatches(description)) { + final isStackTraceLine = stackTraceLineRegex.hasMatch(match[0] ?? ''); + if (isStackTraceLine) break; + message += '${match[0]}\n'; + } + return message; + } } diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index f4fdea39a..e39e7ec17 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -84,6 +84,20 @@ void main() { }); }); + group('mapExceptionStackTrace', () { + test('with a stack trace', () async { + final result = + await inspector.mapExceptionStackTrace(jsExceptionWithStackTrace); + expect(result, equals(formattedWithStackTrace)); + }); + + test('without a stack trace', () async { + final result = + await inspector.mapExceptionStackTrace(jsExceptionNoStackTrace); + expect(result, equals(formattedNoStackTrace)); + }); + }); + test('send toString', () async { final remoteObject = await libraryPublicFinal(); final toString = @@ -203,3 +217,29 @@ void main() { }); }); } + +final jsExceptionWithStackTrace = ''' +Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +false +"THIS IS THE ASSERT MESSAGE" + at Object.assertFailed (org-dartlang-app:///web/scopes_main.dart.js:5297:15) +'''; + +final formattedWithStackTrace = ''' +Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +false +"THIS IS THE ASSERT MESSAGE" +org-dartlang-app:///web/scopes_main.dart.js 5297:15 assertFailed +'''; + +final jsExceptionNoStackTrace = ''' +Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +false +"THIS IS THE ASSERT MESSAGE" +'''; + +final formattedNoStackTrace = ''' +Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +false +"THIS IS THE ASSERT MESSAGE" +'''; From 0752841c8d59bd4876d9c38feb7586f7dfc4709c Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 9 Nov 2022 10:26:16 -0800 Subject: [PATCH 2/5] Remove unnecessary import --- dwds/lib/src/debugging/inspector.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index 63cb258b7..cc619dfba 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file.import 'dart:async'; -import 'dart:math'; - import 'package:async/async.dart'; import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; From ce763c0fd7559328b2245cc1ce5e2e8935da98ac Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:08:16 -0800 Subject: [PATCH 3/5] Add more tests --- dwds/test/inspector_test.dart | 48 ++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index e39e7ec17..ed0c4d19b 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -85,16 +85,24 @@ void main() { }); group('mapExceptionStackTrace', () { - test('with a stack trace', () async { - final result = - await inspector.mapExceptionStackTrace(jsExceptionWithStackTrace); - expect(result, equals(formattedWithStackTrace)); + test('multi-line exception with a stack trace', () async { + final result = await inspector + .mapExceptionStackTrace(jsMultiLineExceptionWithStackTrace); + expect(result, equals(formattedMultiLineExceptionWithStackTrace)); }); - test('without a stack trace', () async { - final result = - await inspector.mapExceptionStackTrace(jsExceptionNoStackTrace); - expect(result, equals(formattedNoStackTrace)); + test('multi-line exception without a stack trace', () async { + final result = await inspector + .mapExceptionStackTrace(jsMultiLineExceptionNoStackTrace); + expect(result, equals(formattedMultiLineExceptionNoStackTrace)); + }); + + test('single-line exception with a stack trace', () async { + final result = await inspector + .mapExceptionStackTrace(jsSingleLineExceptionWithStackTrace); + print('RESULT IS'); + print(result); + expect(result, equals(formattedSingleLineExceptionWithStackTrace)); }); }); @@ -218,28 +226,44 @@ void main() { }); } -final jsExceptionWithStackTrace = ''' +final jsMultiLineExceptionWithStackTrace = ''' Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" at Object.assertFailed (org-dartlang-app:///web/scopes_main.dart.js:5297:15) '''; -final formattedWithStackTrace = ''' +final formattedMultiLineExceptionWithStackTrace = ''' Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" org-dartlang-app:///web/scopes_main.dart.js 5297:15 assertFailed '''; -final jsExceptionNoStackTrace = ''' +final jsMultiLineExceptionNoStackTrace = ''' Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" '''; -final formattedNoStackTrace = ''' +final formattedMultiLineExceptionNoStackTrace = ''' Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" '''; + +final jsSingleLineExceptionWithStackTrace = ''' +Error: Unexpected null value. + at Object.throw_ [as throw] (http://localhost:63236/dart_sdk.js:5379:11) + at Object.nullCheck (http://localhost:63236/dart_sdk.js:5696:30) + at main (http://localhost:63236/packages/tmpapp/main.dart.lib.js:374:10) + at http://localhost:63236/web_entrypoint.dart.lib.js:41:33 +'''; + +final formattedSingleLineExceptionWithStackTrace = ''' +Error: Unexpected null value. +http://localhost:63236/dart_sdk.js 5379:11 throw_ +http://localhost:63236/dart_sdk.js 5696:30 nullCheck +http://localhost:63236/packages/tmpapp/main.dart.lib.js 374:10 main +http://localhost:63236/web_entrypoint.dart.lib.js 41:33 +'''; From 2f3ba9a982e377c366ffdea8cf5472d4fbd7d0e1 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:09:50 -0800 Subject: [PATCH 4/5] Remove print statements --- dwds/test/inspector_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index ed0c4d19b..3999296d1 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -100,8 +100,6 @@ void main() { test('single-line exception with a stack trace', () async { final result = await inspector .mapExceptionStackTrace(jsSingleLineExceptionWithStackTrace); - print('RESULT IS'); - print(result); expect(result, equals(formattedSingleLineExceptionWithStackTrace)); }); }); From 39f43b36d1a60076d44ac22cf59097090e4a3bb9 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Thu, 10 Nov 2022 09:55:05 -0800 Subject: [PATCH 5/5] Update CHANGELOG --- dwds/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 2c83848b2..654ab7754 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -6,6 +6,8 @@ internally or externally. - Fix null cast error on expression evaluations after dwds fails to find class metadata. +- Include the entire exception description up to the stacktrace in + `mapExceptionStackTrace`. ## 16.0.1