Skip to content

Commit ea2fa95

Browse files
committed
suppress stack when SentryError isn't an error
1 parent 031e091 commit ea2fa95

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/core/src/baseclient.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,16 @@ 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 sentryError = reason as SentryError;
590+
if (sentryError.logLevel === 'log') {
591+
logger.log(sentryError.message);
592+
} else {
593+
logger.warn(sentryError);
594+
}
595+
}
587596
return undefined;
588597
},
589598
);
@@ -606,7 +615,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
606615
const { beforeSend, sampleRate } = this.getOptions();
607616

608617
if (!this._isEnabled()) {
609-
return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.'));
618+
return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.', 'log'));
610619
}
611620

612621
const isTransaction = event.type === 'transaction';
@@ -618,6 +627,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
618627
return rejectedSyncPromise(
619628
new SentryError(
620629
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
630+
'log',
621631
),
622632
);
623633
}
@@ -626,7 +636,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
626636
.then(prepared => {
627637
if (prepared === null) {
628638
this.recordDroppedEvent('event_processor', event.type || 'error');
629-
throw new SentryError('An event processor returned null, will not send event.');
639+
throw new SentryError('An event processor returned null, will not send event.', 'log');
630640
}
631641

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

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

packages/utils/src/error.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import type { ConsoleLevel } from './logger';
2+
13
/** An error emitted by Sentry SDKs and related utilities. */
24
export class SentryError extends Error {
35
/** Display name of this error instance. */
46
public name: string;
57

6-
public constructor(public message: string) {
8+
public logLevel: ConsoleLevel;
9+
10+
public constructor(public message: string, logLevel: ConsoleLevel = 'warn') {
711
super(message);
812

913
this.name = new.target.prototype.constructor.name;
1014
Object.setPrototypeOf(this, new.target.prototype);
15+
this.logLevel = logLevel;
1116
}
1217
}

0 commit comments

Comments
 (0)