Skip to content

Commit 9074f4e

Browse files
AbhiPrasadonurtemizkan
authored andcommitted
ref(core): Remove optional chaining (#4291)
1 parent 9f3ede8 commit 9074f4e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/core/src/baseclient.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
150150
*/
151151
public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined {
152152
// ensure we haven't captured this very object before
153-
if (hint?.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
153+
if (hint && hint.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
154154
logger.log(ALREADY_SEEN_ERROR);
155155
return;
156156
}
@@ -523,6 +523,15 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
523523
const { beforeSend, sampleRate } = this.getOptions();
524524
const transport = this.getTransport();
525525

526+
type RecordLostEvent = NonNullable<Transport['recordLostEvent']>;
527+
type RecordLostEventParams = Parameters<RecordLostEvent>;
528+
529+
function recordLostEvent(outcome: RecordLostEventParams[0], category: RecordLostEventParams[1]): void {
530+
if (transport.recordLostEvent) {
531+
transport.recordLostEvent(outcome, category);
532+
}
533+
}
534+
526535
if (!this._isEnabled()) {
527536
return SyncPromise.reject(new SentryError('SDK not enabled, will not capture event.'));
528537
}
@@ -532,7 +541,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
532541
// 0.0 === 0% events are sent
533542
// Sampling for transaction happens somewhere else
534543
if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) {
535-
transport.recordLostEvent?.(Outcome.SampleRate, 'event');
544+
recordLostEvent(Outcome.SampleRate, 'event');
536545
return SyncPromise.reject(
537546
new SentryError(
538547
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
@@ -543,7 +552,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
543552
return this._prepareEvent(event, scope, hint)
544553
.then(prepared => {
545554
if (prepared === null) {
546-
transport.recordLostEvent?.(Outcome.EventProcessor, event.type || 'event');
555+
recordLostEvent(Outcome.EventProcessor, event.type || 'event');
547556
throw new SentryError('An event processor returned null, will not send event.');
548557
}
549558

@@ -557,7 +566,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
557566
})
558567
.then(processedEvent => {
559568
if (processedEvent === null) {
560-
transport.recordLostEvent?.(Outcome.BeforeSend, event.type || 'event');
569+
recordLostEvent(Outcome.BeforeSend, event.type || 'event');
561570
throw new SentryError('`beforeSend` returned `null`, will not send event.');
562571
}
563572

packages/core/src/integrations/inboundfilters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class InboundFilters implements Integration {
194194
for (let i = frames.length - 1; i >= 0; i--) {
195195
const frame = frames[i];
196196

197-
if (frame?.filename !== '<anonymous>' && frame?.filename !== '[native code]') {
197+
if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {
198198
return frame.filename || null;
199199
}
200200
}

packages/core/src/sdk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export function initAndBind<F extends Client, O extends Options>(clientClass: Cl
1717
logger.enable();
1818
}
1919
const hub = getCurrentHub();
20-
hub.getScope()?.update(options.initialScope);
20+
const scope = hub.getScope();
21+
if (scope) {
22+
scope.update(options.initialScope);
23+
}
2124
const client = new clientClass(options);
2225
hub.bindClient(client);
2326
}

0 commit comments

Comments
 (0)