@@ -53,7 +53,6 @@ import {
5353import { createClientReportEnvelope } from './utils-hoist/clientreport' ;
5454import { dsnToString , makeDsn } from './utils-hoist/dsn' ;
5555import { addItemToEnvelope , createAttachmentEnvelopeItem } from './utils-hoist/envelope' ;
56- import { SentryError } from './utils-hoist/error' ;
5756import { isParameterizedString , isPlainObject , isPrimitive , isThenable } from './utils-hoist/is' ;
5857import { logger } from './utils-hoist/logger' ;
5958import { checkOrSetAlreadyCaught , uuid4 } from './utils-hoist/misc' ;
@@ -69,6 +68,41 @@ import { _getSpanForScope } from './utils/spanOnScope';
6968const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured." ;
7069const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing or non-string release' ;
7170
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+
72106/**
73107 * Base implementation for all JavaScript SDK clients.
74108 *
@@ -975,10 +1009,10 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
9751009 } ,
9761010 reason => {
9771011 if ( DEBUG_BUILD ) {
978- // If something's gone wrong, log the error as a warning. If it's just us having used a `SentryError` for
979- // control flow, log just the message (no stack) as a log-level log.
980- if ( reason instanceof SentryError && reason . logLevel === 'log' ) {
1012+ if ( _isDoNotSendEventError ( reason ) ) {
9811013 logger . log ( reason . message ) ;
1014+ } else if ( _isInternalError ( reason ) ) {
1015+ logger . warn ( reason . message ) ;
9821016 } else {
9831017 logger . warn ( reason ) ;
9841018 }
@@ -1022,9 +1056,8 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10221056 if ( isError && typeof parsedSampleRate === 'number' && Math . random ( ) > parsedSampleRate ) {
10231057 this . recordDroppedEvent ( 'sample_rate' , 'error' ) ;
10241058 return rejectedSyncPromise (
1025- new SentryError (
1059+ _makeDoNotSendEventError (
10261060 `Discarding event because it's not included in the random sample (sampling rate = ${ sampleRate } )` ,
1027- 'log' ,
10281061 ) ,
10291062 ) ;
10301063 }
@@ -1035,7 +1068,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10351068 . then ( prepared => {
10361069 if ( prepared === null ) {
10371070 this . recordDroppedEvent ( 'event_processor' , dataCategory ) ;
1038- throw new SentryError ( 'An event processor returned `null`, will not send event.' , 'log ') ;
1071+ throw _makeDoNotSendEventError ( 'An event processor returned `null`, will not send event.' ) ;
10391072 }
10401073
10411074 const isInternalException = hint . data && ( hint . data as { __sentry__ : boolean } ) . __sentry__ === true ;
@@ -1055,7 +1088,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10551088 const spanCount = 1 + spans . length ;
10561089 this . recordDroppedEvent ( 'before_send' , 'span' , spanCount ) ;
10571090 }
1058- throw new SentryError ( `${ beforeSendLabel } returned \`null\`, will not send event.` , 'log' ) ;
1091+ throw _makeDoNotSendEventError ( `${ beforeSendLabel } returned \`null\`, will not send event.` ) ;
10591092 }
10601093
10611094 const session = currentScope . getSession ( ) || isolationScope . getSession ( ) ;
@@ -1089,7 +1122,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10891122 return processedEvent ;
10901123 } )
10911124 . then ( null , reason => {
1092- if ( reason instanceof SentryError ) {
1125+ if ( _isDoNotSendEventError ( reason ) || _isInternalError ( reason ) ) {
10931126 throw reason ;
10941127 }
10951128
@@ -1099,7 +1132,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10991132 } ,
11001133 originalException : reason ,
11011134 } ) ;
1102- throw new SentryError (
1135+ throw _makeInternalError (
11031136 `Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${ reason } ` ,
11041137 ) ;
11051138 } ) ;
@@ -1205,16 +1238,16 @@ function _validateBeforeSendResult(
12051238 return beforeSendResult . then (
12061239 event => {
12071240 if ( ! isPlainObject ( event ) && event !== null ) {
1208- throw new SentryError ( invalidValueError ) ;
1241+ throw _makeInternalError ( invalidValueError ) ;
12091242 }
12101243 return event ;
12111244 } ,
12121245 e => {
1213- throw new SentryError ( `${ beforeSendLabel } rejected with ${ e } ` ) ;
1246+ throw _makeInternalError ( `${ beforeSendLabel } rejected with ${ e } ` ) ;
12141247 } ,
12151248 ) ;
12161249 } else if ( ! isPlainObject ( beforeSendResult ) && beforeSendResult !== null ) {
1217- throw new SentryError ( invalidValueError ) ;
1250+ throw _makeInternalError ( invalidValueError ) ;
12181251 }
12191252 return beforeSendResult ;
12201253}
0 commit comments