@@ -157,7 +157,8 @@ export function track(
157
157
// Update before calling callback in case it schedules follow-up work.
158
158
interaction . __count = 1 ;
159
159
160
- let caughtError = null ;
160
+ let caughtError ;
161
+ let didCatch = false ;
161
162
let returnValue ;
162
163
const subscriber = ( ( subscriberRef : any ) : SubscriberRef ) . current ;
163
164
@@ -166,13 +167,15 @@ export function track(
166
167
subscriber . onInteractionTracked ( interaction ) ;
167
168
subscriber . onWorkStarted ( interactions , threadID ) ;
168
169
} catch ( error ) {
170
+ didCatch = true ;
169
171
caughtError = caughtError || error ;
170
172
}
171
173
}
172
174
173
175
try {
174
176
returnValue = callback ( ) ;
175
177
} catch ( error ) {
178
+ didCatch = true ;
176
179
caughtError = caughtError || error ;
177
180
}
178
181
@@ -182,6 +185,7 @@ export function track(
182
185
try {
183
186
subscriber . onWorkStopped ( interactions , threadID ) ;
184
187
} catch ( error ) {
188
+ didCatch = true ;
185
189
caughtError = caughtError || error ;
186
190
}
187
191
}
@@ -194,11 +198,12 @@ export function track(
194
198
try {
195
199
subscriber . onInteractionScheduledWorkCompleted ( interaction ) ;
196
200
} catch ( error ) {
201
+ didCatch = true ;
197
202
caughtError = caughtError || error ;
198
203
}
199
204
}
200
205
201
- if ( caughtError !== null ) {
206
+ if ( didCatch ) {
202
207
throw caughtError ;
203
208
} else {
204
209
return returnValue ;
@@ -249,20 +254,23 @@ export function wrap(
249
254
const subscriber = ( ( subscriberRef : any ) : SubscriberRef ) . current ;
250
255
251
256
try {
252
- let caughtError = null ;
257
+ let caughtError ;
258
+ let didCatch = false ;
253
259
let returnValue ;
254
260
255
261
try {
256
262
if ( subscriber !== null ) {
257
263
subscriber . onWorkStarted ( wrappedInteractions , threadID ) ;
258
264
}
259
265
} catch ( error ) {
266
+ didCatch = true ;
260
267
caughtError = caughtError || error ;
261
268
}
262
269
263
270
try {
264
271
returnValue = callback ( ...args ) ;
265
272
} catch ( error ) {
273
+ didCatch = true ;
266
274
caughtError = caughtError || error ;
267
275
}
268
276
@@ -273,10 +281,11 @@ export function wrap(
273
281
subscriber . onWorkStopped ( wrappedInteractions , threadID ) ;
274
282
}
275
283
} catch ( error ) {
284
+ didCatch = true ;
276
285
caughtError = caughtError || error ;
277
286
}
278
287
279
- if ( caughtError !== null ) {
288
+ if ( didCatch ) {
280
289
throw caughtError ;
281
290
} else {
282
291
return returnValue ;
0 commit comments