@@ -53,7 +53,6 @@ import {
53
53
import { createClientReportEnvelope } from './utils-hoist/clientreport' ;
54
54
import { dsnToString , makeDsn } from './utils-hoist/dsn' ;
55
55
import { addItemToEnvelope , createAttachmentEnvelopeItem } from './utils-hoist/envelope' ;
56
- import { SentryError } from './utils-hoist/error' ;
57
56
import { isParameterizedString , isPlainObject , isPrimitive , isThenable } from './utils-hoist/is' ;
58
57
import { logger } from './utils-hoist/logger' ;
59
58
import { checkOrSetAlreadyCaught , uuid4 } from './utils-hoist/misc' ;
@@ -69,6 +68,41 @@ import { _getSpanForScope } from './utils/spanOnScope';
69
68
const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured." ;
70
69
const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing or non-string release' ;
71
70
71
+ const INTERNAL_ERROR_SYMBOL = Symbol . for ( 'SentryInternalError' ) ;
72
+ const DO_NOT_SEND_EVENT_SYMBOL = Symbol . for ( 'SentryDoNotSendEventError' ) ;
73
+
74
+ interface InternalError {
75
+ message : string ;
76
+ [ INTERNAL_ERROR_SYMBOL ] : true ;
77
+ }
78
+
79
+ interface DoNotSendEventError {
80
+ message : string ;
81
+ [ DO_NOT_SEND_EVENT_SYMBOL ] : true ;
82
+ }
83
+
84
+ function makeInternalError ( message : string ) : InternalError {
85
+ return {
86
+ message,
87
+ [ INTERNAL_ERROR_SYMBOL ] : true ,
88
+ } ;
89
+ }
90
+
91
+ function makeDoNotSendEventError ( message : string ) : DoNotSendEventError {
92
+ return {
93
+ message,
94
+ [ DO_NOT_SEND_EVENT_SYMBOL ] : true ,
95
+ } ;
96
+ }
97
+
98
+ function isInternalError ( error : unknown ) : error is InternalError {
99
+ return ! ! error && typeof error === 'object' && INTERNAL_ERROR_SYMBOL in error ;
100
+ }
101
+
102
+ function isDoNotSendEventError ( error : unknown ) : error is DoNotSendEventError {
103
+ return ! ! error && typeof error === 'object' && DO_NOT_SEND_EVENT_SYMBOL in error ;
104
+ }
105
+
72
106
/**
73
107
* Base implementation for all JavaScript SDK clients.
74
108
*
@@ -963,10 +997,10 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
963
997
} ,
964
998
reason => {
965
999
if ( DEBUG_BUILD ) {
966
- // If something's gone wrong, log the error as a warning. If it's just us having used a `SentryError` for
967
- // control flow, log just the message (no stack) as a log-level log.
968
- if ( reason instanceof SentryError && reason . logLevel === 'log' ) {
1000
+ if ( isDoNotSendEventError ( reason ) ) {
969
1001
logger . log ( reason . message ) ;
1002
+ } else if ( isInternalError ( reason ) ) {
1003
+ logger . warn ( reason . message ) ;
970
1004
} else {
971
1005
logger . warn ( reason ) ;
972
1006
}
@@ -1010,9 +1044,8 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
1010
1044
if ( isError && typeof parsedSampleRate === 'number' && Math . random ( ) > parsedSampleRate ) {
1011
1045
this . recordDroppedEvent ( 'sample_rate' , 'error' ) ;
1012
1046
return rejectedSyncPromise (
1013
- new SentryError (
1047
+ makeDoNotSendEventError (
1014
1048
`Discarding event because it's not included in the random sample (sampling rate = ${ sampleRate } )` ,
1015
- 'log' ,
1016
1049
) ,
1017
1050
) ;
1018
1051
}
@@ -1023,7 +1056,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
1023
1056
. then ( prepared => {
1024
1057
if ( prepared === null ) {
1025
1058
this . recordDroppedEvent ( 'event_processor' , dataCategory ) ;
1026
- throw new SentryError ( 'An event processor returned `null`, will not send event.' , 'log ') ;
1059
+ throw makeDoNotSendEventError ( 'An event processor returned `null`, will not send event.' ) ;
1027
1060
}
1028
1061
1029
1062
const isInternalException = hint . data && ( hint . data as { __sentry__ : boolean } ) . __sentry__ === true ;
@@ -1043,7 +1076,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
1043
1076
const spanCount = 1 + spans . length ;
1044
1077
this . recordDroppedEvent ( 'before_send' , 'span' , spanCount ) ;
1045
1078
}
1046
- throw new SentryError ( `${ beforeSendLabel } returned \`null\`, will not send event.` , 'log' ) ;
1079
+ throw makeDoNotSendEventError ( `${ beforeSendLabel } returned \`null\`, will not send event.` ) ;
1047
1080
}
1048
1081
1049
1082
const session = currentScope . getSession ( ) || isolationScope . getSession ( ) ;
@@ -1077,7 +1110,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
1077
1110
return processedEvent ;
1078
1111
} )
1079
1112
. then ( null , reason => {
1080
- if ( reason instanceof SentryError ) {
1113
+ if ( isDoNotSendEventError ( reason ) || isInternalError ( reason ) ) {
1081
1114
throw reason ;
1082
1115
}
1083
1116
@@ -1087,7 +1120,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
1087
1120
} ,
1088
1121
originalException : reason ,
1089
1122
} ) ;
1090
- throw new SentryError (
1123
+ throw makeInternalError (
1091
1124
`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${ reason } ` ,
1092
1125
) ;
1093
1126
} ) ;
@@ -1192,17 +1225,17 @@ function _validateBeforeSendResult(
1192
1225
if ( isThenable ( beforeSendResult ) ) {
1193
1226
return beforeSendResult . then (
1194
1227
event => {
1195
- if ( ! isPlainObject ( event ) && event !== null ) {
1196
- throw new SentryError ( invalidValueError ) ;
1228
+ if ( ! isPlainObject ( event ) && event ) {
1229
+ throw makeInternalError ( invalidValueError ) ;
1197
1230
}
1198
1231
return event ;
1199
1232
} ,
1200
1233
e => {
1201
- throw new SentryError ( `${ beforeSendLabel } rejected with ${ e } ` ) ;
1234
+ throw makeInternalError ( `${ beforeSendLabel } rejected with ${ e } ` ) ;
1202
1235
} ,
1203
1236
) ;
1204
- } else if ( ! isPlainObject ( beforeSendResult ) && beforeSendResult !== null ) {
1205
- throw new SentryError ( invalidValueError ) ;
1237
+ } else if ( ! isPlainObject ( beforeSendResult ) && beforeSendResult ) {
1238
+ throw makeInternalError ( invalidValueError ) ;
1206
1239
}
1207
1240
return beforeSendResult ;
1208
1241
}
0 commit comments