File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed
packages/serverless/src/gcpfunction Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change 11import { captureException , flush , getCurrentHub } from '@sentry/node' ;
2- import { logger } from '@sentry/utils' ;
2+ import { isThenable , logger } from '@sentry/utils' ;
33
44import { domainify , getActiveDomain , proxyFunction } from '../utils' ;
55import type { CloudEventFunction , CloudEventFunctionWithCallback , WrapperOptions } from './general' ;
@@ -49,8 +49,6 @@ function _wrapCloudEventFunction(
4949
5050 const activeDomain = getActiveDomain ( ) ! ; // eslint-disable-line @typescript-eslint/no-non-null-assertion
5151
52- activeDomain . on ( 'error' , captureException ) ;
53-
5452 const newCallback = activeDomain . bind ( ( ...args : unknown [ ] ) => {
5553 if ( args [ 0 ] !== null && args [ 0 ] !== undefined ) {
5654 captureException ( args [ 0 ] ) ;
@@ -67,7 +65,22 @@ function _wrapCloudEventFunction(
6765 } ) ;
6866
6967 if ( fn . length > 1 ) {
70- return ( fn as CloudEventFunctionWithCallback ) ( context , newCallback ) ;
68+ let fnResult ;
69+ try {
70+ fnResult = ( fn as CloudEventFunctionWithCallback ) ( context , newCallback ) ;
71+ } catch ( err ) {
72+ captureException ( err ) ;
73+ throw err ;
74+ }
75+
76+ if ( isThenable ( fnResult ) ) {
77+ fnResult . then ( null , err => {
78+ captureException ( err ) ;
79+ throw err ;
80+ } ) ;
81+ }
82+
83+ return fnResult ;
7184 }
7285
7386 return Promise . resolve ( )
Original file line number Diff line number Diff line change 11import { captureException , flush , getCurrentHub } from '@sentry/node' ;
2- import { logger } from '@sentry/utils' ;
2+ import { isThenable , logger } from '@sentry/utils' ;
33
44import { domainify , getActiveDomain , proxyFunction } from '../utils' ;
55import type { EventFunction , EventFunctionWithCallback , WrapperOptions } from './general' ;
@@ -51,8 +51,6 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
5151
5252 const activeDomain = getActiveDomain ( ) ! ; // eslint-disable-line @typescript-eslint/no-non-null-assertion
5353
54- activeDomain . on ( 'error' , captureException ) ;
55-
5654 const newCallback = activeDomain . bind ( ( ...args : unknown [ ] ) => {
5755 if ( args [ 0 ] !== null && args [ 0 ] !== undefined ) {
5856 captureException ( args [ 0 ] ) ;
@@ -71,7 +69,22 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
7169 } ) ;
7270
7371 if ( fn . length > 2 ) {
74- return ( fn as EventFunctionWithCallback ) ( data , context , newCallback ) ;
72+ let fnResult ;
73+ try {
74+ fnResult = ( fn as EventFunctionWithCallback ) ( data , context , newCallback ) ;
75+ } catch ( err ) {
76+ captureException ( err ) ;
77+ throw err ;
78+ }
79+
80+ if ( isThenable ( fnResult ) ) {
81+ fnResult . then ( null , err => {
82+ captureException ( err ) ;
83+ throw err ;
84+ } ) ;
85+ }
86+
87+ return fnResult ;
7588 }
7689
7790 return Promise . resolve ( )
You can’t perform that action at this time.
0 commit comments