@@ -39,6 +39,12 @@ typedef StreamNotify = void Function(String streamId, Event event);
39
39
/// This may be null during a hot restart or page refresh.
40
40
typedef AppInspectorProvider = AppInspector Function ();
41
41
42
+ /// JavaScript expression that evaluates to the Dart stack trace mapper.
43
+ const stackTraceMapperExpression = '\$ dartStackTraceUtility.mapper' ;
44
+
45
+ /// Regex used to extract the message from an exception description.
46
+ final exceptionMessageRegex = RegExp (r'^.*$' , multiLine: true );
47
+
42
48
/// A proxy from the chrome debug protocol to the dart vm service protocol.
43
49
class ChromeProxyService implements VmServiceInterface {
44
50
/// Cache of all existing StreamControllers.
@@ -834,15 +840,30 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
834
840
..timestamp = e.timestamp.toInt ());
835
841
});
836
842
if (includeExceptions) {
837
- exceptionsSubscription = remoteDebugger.onExceptionThrown.listen ((e) {
843
+ exceptionsSubscription =
844
+ remoteDebugger.onExceptionThrown.listen ((e) async {
838
845
var isolate = _inspector? .isolate;
839
846
if (isolate == null ) return ;
847
+ var description = e.exceptionDetails.exception.description;
848
+ if (description != null ) {
849
+ // Map the exception stack trace to a Dart stack.
850
+ RemoteObject mapperResult;
851
+ try {
852
+ mapperResult = await _inspector.jsCallFunction (
853
+ stackTraceMapperExpression, < Object > [description]);
854
+ } catch (_) {}
855
+ var mappedStack = mapperResult? .value? .toString ();
856
+ if (mappedStack != null && mappedStack.isNotEmpty) {
857
+ var message =
858
+ exceptionMessageRegex.firstMatch (description)? .group (0 ) ?? '' ;
859
+ description = '${e .exceptionDetails .text } $message \n $mappedStack ' ;
860
+ }
861
+ }
840
862
controller.add (Event (
841
863
kind: EventKind .kWriteEvent,
842
864
timestamp: DateTime .now ().millisecondsSinceEpoch,
843
865
isolate: _inspector.isolateRef)
844
- ..bytes = base64.encode (
845
- utf8.encode (e.exceptionDetails.exception.description ?? '' )));
866
+ ..bytes = base64.encode (utf8.encode (description ?? '' )));
846
867
});
847
868
}
848
869
});
0 commit comments