1
1
'use strict'
2
2
3
+ const lock = require ( 'mutexify/promise' ) ( )
3
4
const { getGeneratedPosition } = require ( './source-maps' )
4
- const lock = require ( './lock' ) ( )
5
5
const session = require ( './session' )
6
6
const { compile : compileCondition , compileSegments, templateRequiresEvaluation } = require ( './condition' )
7
7
const { MAX_SNAPSHOTS_PER_SECOND_PER_PROBE , MAX_NON_SNAPSHOTS_PER_SECOND_PER_PROBE } = require ( './defaults' )
@@ -64,14 +64,14 @@ async function addBreakpoint (probe) {
64
64
const release = await lock ( )
65
65
66
66
try {
67
- log . debug (
68
- '[debugger:devtools_client] Adding breakpoint at %s:%d:%d (probe: %s, version: %d)' ,
69
- url , lineNumber , columnNumber , probe . id , probe . version
70
- )
71
-
72
67
const locationKey = generateLocationKey ( scriptId , lineNumber , columnNumber )
73
68
const breakpoint = locationToBreakpoint . get ( locationKey )
74
69
70
+ log . debug (
71
+ '[debugger:devtools_client] %s breakpoint at %s:%d:%d (probe: %s, version: %d)' ,
72
+ breakpoint ? 'Updating' : 'Adding' , url , lineNumber , columnNumber , probe . id , probe . version
73
+ )
74
+
75
75
if ( breakpoint ) {
76
76
// A breakpoint already exists at this location, so we need to add the probe to the existing breakpoint
77
77
await updateBreakpoint ( breakpoint , probe )
@@ -82,10 +82,15 @@ async function addBreakpoint (probe) {
82
82
lineNumber : lineNumber - 1 , // Beware! lineNumber is zero-indexed
83
83
columnNumber
84
84
}
85
- const result = await session . post ( 'Debugger.setBreakpoint' , {
86
- location,
87
- condition : probe . condition
88
- } )
85
+ let result
86
+ try {
87
+ result = await session . post ( 'Debugger.setBreakpoint' , {
88
+ location,
89
+ condition : probe . condition
90
+ } )
91
+ } catch ( err ) {
92
+ throw new Error ( `Error setting breakpoint for probe ${ probe . id } ` , { cause : err } )
93
+ }
89
94
probeToLocation . set ( probe . id , locationKey )
90
95
locationToBreakpoint . set ( locationKey , { id : result . breakpointId , location, locationKey } )
91
96
breakpointToProbes . set ( result . breakpointId , new Map ( [ [ probe . id , probe ] ] ) )
@@ -120,7 +125,11 @@ async function removeBreakpoint ({ id }) {
120
125
if ( breakpointToProbes . size === 0 ) {
121
126
await stop ( ) // TODO: Will this actually delete the breakpoint?
122
127
} else {
123
- await session . post ( 'Debugger.removeBreakpoint' , { breakpointId : breakpoint . id } )
128
+ try {
129
+ await session . post ( 'Debugger.removeBreakpoint' , { breakpointId : breakpoint . id } )
130
+ } catch ( err ) {
131
+ throw new Error ( `Error removing breakpoint for probe ${ id } ` , { cause : err } )
132
+ }
124
133
}
125
134
} else {
126
135
await updateBreakpoint ( breakpoint )
@@ -144,12 +153,21 @@ async function updateBreakpoint (breakpoint, probe) {
144
153
const condition = compileCompoundCondition ( Array . from ( probesAtLocation . values ( ) ) )
145
154
146
155
if ( condition || conditionBeforeNewProbe !== condition ) {
147
- await session . post ( 'Debugger.removeBreakpoint' , { breakpointId : breakpoint . id } )
156
+ try {
157
+ await session . post ( 'Debugger.removeBreakpoint' , { breakpointId : breakpoint . id } )
158
+ } catch ( err ) {
159
+ throw new Error ( `Error removing breakpoint for probe ${ probe . id } ` , { cause : err } )
160
+ }
148
161
breakpointToProbes . delete ( breakpoint . id )
149
- const result = await session . post ( 'Debugger.setBreakpoint' , {
150
- location : breakpoint . location ,
151
- condition
152
- } )
162
+ let result
163
+ try {
164
+ result = await session . post ( 'Debugger.setBreakpoint' , {
165
+ location : breakpoint . location ,
166
+ condition
167
+ } )
168
+ } catch ( err ) {
169
+ throw new Error ( `Error setting breakpoint for probe ${ probe . id } ` , { cause : err } )
170
+ }
153
171
breakpoint . id = result . breakpointId
154
172
breakpointToProbes . set ( result . breakpointId , probesAtLocation )
155
173
}
0 commit comments