|
4 | 4 |
|
5 | 5 | import 'package:dwds/src/debugging/debugger.dart'; |
6 | 6 | import 'package:dwds/src/utilities/synchronized.dart'; |
| 7 | +import 'package:logging/logging.dart'; |
7 | 8 | import 'package:vm_service/vm_service.dart'; |
8 | 9 | import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; |
9 | 10 |
|
10 | 11 | class FrameComputer { |
| 12 | + static final logger = Logger('FrameComputer'); |
| 13 | + |
11 | 14 | final Debugger debugger; |
12 | 15 |
|
13 | 16 | // To ensure that the frames are computed only once, we use an atomic queue |
@@ -58,12 +61,16 @@ class FrameComputer { |
58 | 61 | Future<void> _collectSyncFrames({int? limit}) async { |
59 | 62 | while (_frameIndex < _callFrames.length) { |
60 | 63 | if (limit != null && _computedFrames.length == limit) return; |
61 | | - |
62 | | - final callFrame = _callFrames[_frameIndex]; |
63 | | - final dartFrame = |
64 | | - await debugger.calculateDartFrameFor(callFrame, _frameIndex++); |
65 | | - if (dartFrame != null) { |
66 | | - _computedFrames.add(dartFrame); |
| 64 | + try { |
| 65 | + final callFrame = _callFrames[_frameIndex]; |
| 66 | + final dartFrame = |
| 67 | + await debugger.calculateDartFrameFor(callFrame, _frameIndex++); |
| 68 | + if (dartFrame != null) { |
| 69 | + _computedFrames.add(dartFrame); |
| 70 | + } |
| 71 | + } catch (e) { |
| 72 | + // If there is an error calculating the frame, then skip it. |
| 73 | + logger.warning('Error calculating sync frame: $e'); |
67 | 74 | } |
68 | 75 | } |
69 | 76 | } |
@@ -93,28 +100,33 @@ class FrameComputer { |
93 | 100 | final asyncFramesToProcess = _asyncFramesToProcess!; |
94 | 101 | // Process a single async frame. |
95 | 102 | if (asyncFramesToProcess.isNotEmpty) { |
96 | | - final callFrame = asyncFramesToProcess.removeAt(0); |
97 | | - final location = WipLocation.fromValues( |
98 | | - callFrame.scriptId, |
99 | | - callFrame.lineNumber, |
100 | | - columnNumber: callFrame.columnNumber, |
101 | | - ); |
102 | | - |
103 | | - final tempWipFrame = WipCallFrame({ |
104 | | - 'url': callFrame.url, |
105 | | - 'functionName': callFrame.functionName, |
106 | | - 'location': location.json, |
107 | | - 'scopeChain': [], |
108 | | - }); |
109 | | - |
110 | | - final frame = await debugger.calculateDartFrameFor( |
111 | | - tempWipFrame, |
112 | | - _frameIndex++, |
113 | | - populateVariables: false, |
114 | | - ); |
115 | | - if (frame != null) { |
116 | | - frame.kind = FrameKind.kAsyncCausal; |
117 | | - _computedFrames.add(frame); |
| 103 | + try { |
| 104 | + final callFrame = asyncFramesToProcess.removeAt(0); |
| 105 | + final location = WipLocation.fromValues( |
| 106 | + callFrame.scriptId, |
| 107 | + callFrame.lineNumber, |
| 108 | + columnNumber: callFrame.columnNumber, |
| 109 | + ); |
| 110 | + |
| 111 | + final tempWipFrame = WipCallFrame({ |
| 112 | + 'url': callFrame.url, |
| 113 | + 'functionName': callFrame.functionName, |
| 114 | + 'location': location.json, |
| 115 | + 'scopeChain': [], |
| 116 | + }); |
| 117 | + |
| 118 | + final frame = await debugger.calculateDartFrameFor( |
| 119 | + tempWipFrame, |
| 120 | + _frameIndex++, |
| 121 | + populateVariables: false, |
| 122 | + ); |
| 123 | + if (frame != null) { |
| 124 | + frame.kind = FrameKind.kAsyncCausal; |
| 125 | + _computedFrames.add(frame); |
| 126 | + } |
| 127 | + } catch (e) { |
| 128 | + // If there is an error calculating the frame, then skip it. |
| 129 | + logger.warning('Error calculating async frame: $e'); |
118 | 130 | } |
119 | 131 | } |
120 | 132 | } |
|
0 commit comments