Skip to content

Commit f9a21f6

Browse files
committed
convert isDebugBuild checks from if blocks to short-circuits
1 parent 523b8bc commit f9a21f6

File tree

9 files changed

+20
-53
lines changed

9 files changed

+20
-53
lines changed

packages/browser/src/helpers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,12 @@ export function injectReportDialog(options: ReportDialogOptions = {}): void {
192192
}
193193

194194
if (!options.eventId) {
195-
if (isDebugBuild()) {
196-
logger.error('Missing eventId option in showReportDialog call');
197-
}
195+
isDebugBuild() && logger.error('Missing eventId option in showReportDialog call');
198196
return;
199197
}
200198

201199
if (!options.dsn) {
202-
if (isDebugBuild()) {
203-
logger.error('Missing dsn option in showReportDialog call');
204-
}
200+
isDebugBuild() && logger.error('Missing dsn option in showReportDialog call');
205201
return;
206202
}
207203

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column
237237
}
238238

239239
function globalHandlerLog(type: string): void {
240-
if (isDebugBuild()) {
241-
logger.log(`Global Handler attached: ${type}`);
242-
}
240+
isDebugBuild() && logger.log(`Global Handler attached: ${type}`);
243241
}
244242

245243
function addMechanismAndCapture(hub: Hub, error: EventHint['originalException'], event: Event, type: string): void {

packages/browser/src/sdk.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ export function flush(timeout?: number): PromiseLike<boolean> {
162162
if (client) {
163163
return client.flush(timeout);
164164
}
165-
if (isDebugBuild()) {
166-
logger.warn('Cannot flush events. No client defined.');
167-
}
165+
isDebugBuild() && logger.warn('Cannot flush events. No client defined.');
168166
return resolvedSyncPromise(false);
169167
}
170168

@@ -181,9 +179,7 @@ export function close(timeout?: number): PromiseLike<boolean> {
181179
if (client) {
182180
return client.close(timeout);
183181
}
184-
if (isDebugBuild()) {
185-
logger.warn('Cannot flush events and disable SDK. No client defined.');
186-
}
182+
isDebugBuild() && logger.warn('Cannot flush events and disable SDK. No client defined.');
187183
return resolvedSyncPromise(false);
188184
}
189185

@@ -212,9 +208,7 @@ function startSessionTracking(): void {
212208
const document = window.document;
213209

214210
if (typeof document === 'undefined') {
215-
if (isDebugBuild()) {
216-
logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
217-
}
211+
isDebugBuild() && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
218212
return;
219213
}
220214

packages/browser/src/transports/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ export function getNativeFetchImplementation(): FetchImpl {
6969
}
7070
document.head.removeChild(sandbox);
7171
} catch (e) {
72-
if (isDebugBuild()) {
72+
isDebugBuild() &&
7373
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
74-
}
7574
}
7675
}
7776

packages/core/src/basebackend.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ export abstract class BaseBackend<O extends Options> implements Backend {
9292
*/
9393
public sendEvent(event: Event): void {
9494
void this._transport.sendEvent(event).then(null, reason => {
95-
if (isDebugBuild()) {
96-
logger.error('Error while sending event:', reason);
97-
}
95+
isDebugBuild() && logger.error('Error while sending event:', reason);
9896
});
9997
}
10098

@@ -103,16 +101,12 @@ export abstract class BaseBackend<O extends Options> implements Backend {
103101
*/
104102
public sendSession(session: Session): void {
105103
if (!this._transport.sendSession) {
106-
if (isDebugBuild()) {
107-
logger.warn("Dropping session because custom transport doesn't implement sendSession");
108-
}
104+
isDebugBuild() && logger.warn("Dropping session because custom transport doesn't implement sendSession");
109105
return;
110106
}
111107

112108
void this._transport.sendSession(session).then(null, reason => {
113-
if (isDebugBuild()) {
114-
logger.error('Error while sending session:', reason);
115-
}
109+
isDebugBuild() && logger.error('Error while sending session:', reason);
116110
});
117111
}
118112

packages/core/src/baseclient.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,12 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
173173
*/
174174
public captureSession(session: Session): void {
175175
if (!this._isEnabled()) {
176-
if (isDebugBuild()) {
177-
logger.warn('SDK not enabled, will not capture session.');
178-
}
176+
isDebugBuild() && logger.warn('SDK not enabled, will not capture session.');
179177
return;
180178
}
181179

182180
if (!(typeof session.release === 'string')) {
183-
if (isDebugBuild()) {
184-
logger.warn('Discarded session because of missing or non-string release');
185-
}
181+
isDebugBuild() && logger.warn('Discarded session because of missing or non-string release');
186182
} else {
187183
this._sendSession(session);
188184
// After sending, we set init false to indicate it's not the first occurrence

packages/core/src/integrations/inboundfilters.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,33 @@ export class InboundFilters implements Integration {
6464
/** JSDoc */
6565
private _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>): boolean {
6666
if (this._isSentryError(event, options)) {
67-
if (isDebugBuild()) {
67+
isDebugBuild() &&
6868
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
69-
}
7069
return true;
7170
}
7271
if (this._isIgnoredError(event, options)) {
73-
if (isDebugBuild()) {
72+
isDebugBuild() &&
7473
logger.warn(
7574
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
7675
);
77-
}
7876
return true;
7977
}
8078
if (this._isDeniedUrl(event, options)) {
81-
if (isDebugBuild()) {
79+
isDebugBuild() &&
8280
logger.warn(
8381
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
8482
event,
8583
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
8684
);
87-
}
8885
return true;
8986
}
9087
if (!this._isAllowedUrl(event, options)) {
91-
if (isDebugBuild()) {
88+
isDebugBuild() &&
9289
logger.warn(
9390
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
9491
event,
9592
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
9693
);
97-
}
9894
return true;
9995
}
10096
return false;
@@ -187,9 +183,7 @@ export class InboundFilters implements Integration {
187183
const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
188184
return [`${value}`, `${type}: ${value}`];
189185
} catch (oO) {
190-
if (isDebugBuild()) {
191-
logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
192-
}
186+
isDebugBuild() && logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
193187
return [];
194188
}
195189
}
@@ -224,9 +218,7 @@ export class InboundFilters implements Integration {
224218
}
225219
return frames ? this._getLastValidUrl(frames) : null;
226220
} catch (oO) {
227-
if (isDebugBuild()) {
228-
logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
229-
}
221+
isDebugBuild() && logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
230222
return null;
231223
}
232224
}

packages/utils/src/instrument.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,11 @@ function triggerHandlers(type: InstrumentHandlerType, data: any): void {
9494
try {
9595
handler(data);
9696
} catch (e) {
97-
if (isDebugBuild()) {
97+
isDebugBuild() &&
9898
logger.error(
9999
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`,
100100
e,
101101
);
102-
}
103102
}
104103
}
105104
}

packages/utils/src/supports.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ export function supportsNativeFetch(): boolean {
113113
}
114114
doc.head.removeChild(sandbox);
115115
} catch (err) {
116-
if (isDebugBuild()) {
116+
isDebugBuild() &&
117117
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
118-
}
119118
}
120119
}
121120

0 commit comments

Comments
 (0)