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 1
1
import { captureException , flush , getCurrentHub } from '@sentry/node' ;
2
- import { logger } from '@sentry/utils' ;
2
+ import { isThenable , logger } from '@sentry/utils' ;
3
3
4
4
import { domainify , getActiveDomain , proxyFunction } from '../utils' ;
5
5
import type { CloudEventFunction , CloudEventFunctionWithCallback , WrapperOptions } from './general' ;
@@ -49,8 +49,6 @@ function _wrapCloudEventFunction(
49
49
50
50
const activeDomain = getActiveDomain ( ) ! ; // eslint-disable-line @typescript-eslint/no-non-null-assertion
51
51
52
- activeDomain . on ( 'error' , captureException ) ;
53
-
54
52
const newCallback = activeDomain . bind ( ( ...args : unknown [ ] ) => {
55
53
if ( args [ 0 ] !== null && args [ 0 ] !== undefined ) {
56
54
captureException ( args [ 0 ] ) ;
@@ -67,7 +65,22 @@ function _wrapCloudEventFunction(
67
65
} ) ;
68
66
69
67
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 ;
71
84
}
72
85
73
86
return Promise . resolve ( )
Original file line number Diff line number Diff line change 1
1
import { captureException , flush , getCurrentHub } from '@sentry/node' ;
2
- import { logger } from '@sentry/utils' ;
2
+ import { isThenable , logger } from '@sentry/utils' ;
3
3
4
4
import { domainify , getActiveDomain , proxyFunction } from '../utils' ;
5
5
import type { EventFunction , EventFunctionWithCallback , WrapperOptions } from './general' ;
@@ -51,8 +51,6 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
51
51
52
52
const activeDomain = getActiveDomain ( ) ! ; // eslint-disable-line @typescript-eslint/no-non-null-assertion
53
53
54
- activeDomain . on ( 'error' , captureException ) ;
55
-
56
54
const newCallback = activeDomain . bind ( ( ...args : unknown [ ] ) => {
57
55
if ( args [ 0 ] !== null && args [ 0 ] !== undefined ) {
58
56
captureException ( args [ 0 ] ) ;
@@ -71,7 +69,22 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
71
69
} ) ;
72
70
73
71
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 ;
75
88
}
76
89
77
90
return Promise . resolve ( )
You can’t perform that action at this time.
0 commit comments