@@ -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,28 @@ ${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 = remoteDebugger.onExceptionThrown.listen ((e) async {
838
844
var isolate = _inspector? .isolate;
839
845
if (isolate == null ) return ;
846
+ String description = e.exceptionDetails.exception.description;
847
+ if (description != null ) {
848
+ // Map the exception stack trace to a Dart stack.
849
+ RemoteObject mapperResult;
850
+ try {
851
+ mapperResult = await _inspector.jsCallFunction (stackTraceMapperExpression, < Object > [description]);
852
+ } catch (_) {}
853
+ String mappedStack = mapperResult? .value? .toString ();
854
+ if (mappedStack != null && mappedStack.isNotEmpty) {
855
+ String message = exceptionMessageRegex.firstMatch (description)? .group (0 ) ?? '' ;
856
+ description = '${e .exceptionDetails .text } $message \n $mappedStack ' ;
857
+ }
858
+ }
840
859
controller.add (Event (
841
860
kind: EventKind .kWriteEvent,
842
861
timestamp: DateTime .now ().millisecondsSinceEpoch,
843
862
isolate: _inspector.isolateRef)
844
863
..bytes = base64.encode (
845
- utf8.encode (e.exceptionDetails.exception. description ?? '' )));
864
+ utf8.encode (description ?? '' )));
846
865
});
847
866
}
848
867
});
0 commit comments