1- import type { Batch , Context } from '@datadog/browser-core'
1+ import type { Batch , Context , ContextValue } from '@datadog/browser-core'
22import { timeStampNow } from '@datadog/js-core/time'
33import { buildTag , generateUUID , globalObject , mergeArrays } from '@datadog/browser-core'
44import type { BrowserWindow , DebuggerInitConfiguration } from '../entries/main'
@@ -205,8 +205,10 @@ export function onReturn(
205205 if ( ! probe . captureSnapshot ) {
206206 const captureExpressionsResult = evaluateCaptureExpressions ( probe , context , captureCtx )
207207 if ( captureExpressionsResult ) {
208- result . return = {
209- captureExpressions : captureExpressionsResult . values ,
208+ if ( captureExpressionsResult . values ) {
209+ result . return = {
210+ captureExpressions : captureExpressionsResult . values ,
211+ }
210212 }
211213 result . evaluationErrors = mergeArrays ( result . evaluationErrors , captureExpressionsResult . evaluationErrors )
212214 if ( captureCtx . timedOut ) {
@@ -288,8 +290,10 @@ export function onThrow(probes: InitializedProbe[], error: unknown, self: any, a
288290 if ( ! probe . captureSnapshot ) {
289291 const captureExpressionsResult = evaluateCaptureExpressions ( probe , context , captureCtx )
290292 if ( captureExpressionsResult ) {
291- result . return = {
292- captureExpressions : captureExpressionsResult . values ,
293+ if ( captureExpressionsResult . values ) {
294+ result . return = {
295+ captureExpressions : captureExpressionsResult . values ,
296+ }
293297 }
294298 result . evaluationErrors = mergeArrays ( result . evaluationErrors , captureExpressionsResult . evaluationErrors )
295299 if ( captureCtx . timedOut ) {
@@ -307,10 +311,13 @@ export function onThrow(probes: InitializedProbe[], error: unknown, self: any, a
307311 }
308312 }
309313
310- result . return = {
311- ...result . return ,
312- arguments : throwArguments ,
313- throwable : formatThrowable ( error ) ,
314+ const throwable = formatThrowable ( error )
315+ if ( throwArguments ) {
316+ result . return = { arguments : throwArguments , throwable }
317+ } else if ( result . return ?. captureExpressions ) {
318+ result . return = { captureExpressions : result . return . captureExpressions , throwable }
319+ } else {
320+ result . return = { throwable }
314321 }
315322
316323 queueDebuggerSnapshot ( probe , result )
@@ -330,6 +337,14 @@ function queueDebuggerSnapshot(probe: InitializedProbe, result: ActiveEntry): vo
330337 }
331338
332339 const version = globalObj . DD_DEBUGGER ! . version
340+ const captures = (
341+ result . entry || result . return
342+ ? {
343+ entry : result . entry ,
344+ return : result . return ,
345+ }
346+ : undefined
347+ ) as ContextValue
333348
334349 const payload : Context = {
335350 message : result . message ,
@@ -360,13 +375,7 @@ function queueDebuggerSnapshot(probe: InitializedProbe, result: ActiveEntry): vo
360375 stack : result . stack ,
361376 language : 'javascript' ,
362377 duration : result . duration === undefined ? undefined : result . duration * 1e6 , // to nanoseconds (might be undefined in case of eval errors)
363- captures :
364- result . entry || result . return
365- ? {
366- entry : result . entry ,
367- return : result . return ,
368- }
369- : undefined ,
378+ captures,
370379 } ,
371380 } ,
372381 }
0 commit comments