Skip to content

Commit fa54f99

Browse files
committed
suppress stack when SentryError isn't an error
1 parent 9339a73 commit fa54f99

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/core/src/baseclient.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
583583
return finalEvent.event_id;
584584
},
585585
reason => {
586-
__DEBUG_BUILD__ && logger.warn(reason);
586+
if (__DEBUG_BUILD__) {
587+
// If something's gone wrong, log the error as a warning. If it's just us having used a `SentryError` for
588+
// control flow, log just the message (no stack) as a log-level log.
589+
const logLevel = (reason as SentryError).logLevel || 'warn';
590+
const logee = logLevel === 'log' ? (reason as SentryError).message : reason;
591+
logger[logLevel as 'log' | 'warn'](logee);
592+
}
587593
return undefined;
588594
},
589595
);
@@ -606,7 +612,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
606612
const { beforeSend, sampleRate } = this.getOptions();
607613

608614
if (!this._isEnabled()) {
609-
return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.'));
615+
return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.', 'log'));
610616
}
611617

612618
const isTransaction = event.type === 'transaction';
@@ -618,6 +624,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
618624
return rejectedSyncPromise(
619625
new SentryError(
620626
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
627+
'log',
621628
),
622629
);
623630
}
@@ -626,7 +633,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
626633
.then(prepared => {
627634
if (prepared === null) {
628635
this.recordDroppedEvent('event_processor', event.type || 'error');
629-
throw new SentryError('An event processor returned null, will not send event.');
636+
throw new SentryError('An event processor returned null, will not send event.', 'log');
630637
}
631638

632639
const isInternalException = hint.data && (hint.data as { __sentry__: boolean }).__sentry__ === true;
@@ -640,7 +647,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
640647
.then(processedEvent => {
641648
if (processedEvent === null) {
642649
this.recordDroppedEvent('before_send', event.type || 'error');
643-
throw new SentryError('`beforeSend` returned `null`, will not send event.');
650+
throw new SentryError('`beforeSend` returned `null`, will not send event.', 'log');
644651
}
645652

646653
const session = scope && scope.getSession();

packages/utils/src/error.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ export class SentryError extends Error {
33
/** Display name of this error instance. */
44
public name: string;
55

6-
public constructor(public message: string) {
6+
public logLevel: string;
7+
8+
public constructor(public message: string, logLevel: string = 'warn') {
79
super(message);
810

911
this.name = new.target.prototype.constructor.name;
1012
Object.setPrototypeOf(this, new.target.prototype);
13+
this.logLevel = logLevel;
1114
}
1215
}

0 commit comments

Comments
 (0)