File tree Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,9 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
5353 public eventFromException ( exception : any , hint ?: EventHint ) : PromiseLike < Event > {
5454 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5555 let ex : any = exception ;
56- const mechanism : Mechanism = {
56+ const providedMechanism : Mechanism | undefined =
57+ hint && hint . data && ( hint . data as { mechanism : Mechanism } ) . mechanism ;
58+ const mechanism : Mechanism = providedMechanism || {
5759 handled : true ,
5860 type : 'generic' ,
5961 } ;
Original file line number Diff line number Diff line change @@ -78,7 +78,10 @@ export class OnUncaughtException implements Integration {
7878 if ( hub . getIntegration ( OnUncaughtException ) ) {
7979 hub . withScope ( ( scope : Scope ) => {
8080 scope . setLevel ( Severity . Fatal ) ;
81- hub . captureException ( error , { originalException : error } ) ;
81+ hub . captureException ( error , {
82+ originalException : error ,
83+ data : { mechanism : { handled : false , type : 'onuncaughtexception' } } ,
84+ } ) ;
8285 if ( ! calledFatalError ) {
8386 calledFatalError = true ;
8487 onFatalError ( error ) ;
Original file line number Diff line number Diff line change @@ -69,7 +69,10 @@ export class OnUnhandledRejection implements Integration {
6969 scope . setExtras ( context . extra ) ;
7070 }
7171
72- hub . captureException ( reason , { originalException : promise } ) ;
72+ hub . captureException ( reason , {
73+ originalException : promise ,
74+ data : { mechanism : { handled : false , type : 'onunhandledrejection' } } ,
75+ } ) ;
7376 } ) ;
7477 /* eslint-disable @typescript-eslint/no-unsafe-member-access */
7578
Original file line number Diff line number Diff line change 1+ import { Hub } from '@sentry/hub' ;
2+
3+ import { OnUncaughtException } from '../src/integrations/onuncaughtexception' ;
4+
5+ jest . mock ( '@sentry/hub' , ( ) => {
6+ // we just want to short-circuit it, so dont worry about types
7+ const original = jest . requireActual ( '@sentry/hub' ) ;
8+ original . Hub . prototype . getIntegration = ( ) => true ;
9+ return {
10+ ...original ,
11+ getCurrentHub : ( ) => new Hub ( ) ,
12+ } ;
13+ } ) ;
14+
15+ describe ( 'uncaught exceptions' , ( ) => {
16+ test ( 'install global listener' , ( ) => {
17+ const integration = new OnUncaughtException ( ) ;
18+ integration . setupOnce ( ) ;
19+ expect ( process . listeners ( 'uncaughtException' ) ) . toHaveLength ( 1 ) ;
20+ } ) ;
21+
22+ test ( 'sendUncaughtException' , ( ) => {
23+ const integration = new OnUncaughtException ( { onFatalError : jest . fn ( ) } ) ;
24+ integration . setupOnce ( ) ;
25+
26+ const captureException = jest . spyOn ( Hub . prototype , 'captureException' ) ;
27+
28+ integration . handler ( { message : 'message' , name : 'name' } ) ;
29+
30+ expect ( captureException . mock . calls [ 0 ] [ 1 ] ?. data ) . toEqual ( {
31+ mechanism : { handled : false , type : 'onuncaughtexception' } ,
32+ } ) ;
33+ } ) ;
34+ } ) ;
You can’t perform that action at this time.
0 commit comments