Skip to content

Commit bc73dc0

Browse files
timfishAbhiPrasad
authored andcommitted
ref(core): Make hint callback argument non-optional (#5141)
1 parent 747f1df commit bc73dc0

File tree

10 files changed

+47
-47
lines changed

10 files changed

+47
-47
lines changed

packages/core/test/lib/integrations/inboundfilters.test.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,16 @@ describe('InboundFilters', () => {
180180
describe('_isSentryError', () => {
181181
it('should work as expected', () => {
182182
const eventProcessor = createInboundFiltersEventProcessor();
183-
expect(eventProcessor(MESSAGE_EVENT)).toBe(MESSAGE_EVENT);
184-
expect(eventProcessor(EXCEPTION_EVENT)).toBe(EXCEPTION_EVENT);
185-
expect(eventProcessor(SENTRY_EVENT)).toBe(null);
183+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(MESSAGE_EVENT);
184+
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(EXCEPTION_EVENT);
185+
expect(eventProcessor(SENTRY_EVENT, {})).toBe(null);
186186
});
187187

188188
it('should be configurable', () => {
189189
const eventProcessor = createInboundFiltersEventProcessor({ ignoreInternal: false });
190-
expect(eventProcessor(MESSAGE_EVENT)).toBe(MESSAGE_EVENT);
191-
expect(eventProcessor(EXCEPTION_EVENT)).toBe(EXCEPTION_EVENT);
192-
expect(eventProcessor(SENTRY_EVENT)).toBe(SENTRY_EVENT);
190+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(MESSAGE_EVENT);
191+
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(EXCEPTION_EVENT);
192+
expect(eventProcessor(SENTRY_EVENT, {})).toBe(SENTRY_EVENT);
193193
});
194194
});
195195

@@ -198,29 +198,29 @@ describe('InboundFilters', () => {
198198
const eventProcessor = createInboundFiltersEventProcessor({
199199
ignoreErrors: ['capture'],
200200
});
201-
expect(eventProcessor(MESSAGE_EVENT)).toBe(null);
201+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(null);
202202
});
203203

204204
it('string filter with exact match', () => {
205205
const eventProcessor = createInboundFiltersEventProcessor({
206206
ignoreErrors: ['captureMessage'],
207207
});
208-
expect(eventProcessor(MESSAGE_EVENT)).toBe(null);
208+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(null);
209209
});
210210

211211
it('regexp filter with partial match', () => {
212212
const eventProcessor = createInboundFiltersEventProcessor({
213213
ignoreErrors: [/capture/],
214214
});
215-
expect(eventProcessor(MESSAGE_EVENT)).toBe(null);
215+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(null);
216216
});
217217

218218
it('regexp filter with exact match', () => {
219219
const eventProcessor = createInboundFiltersEventProcessor({
220220
ignoreErrors: [/^captureMessage$/],
221221
});
222-
expect(eventProcessor(MESSAGE_EVENT)).toBe(null);
223-
expect(eventProcessor(MESSAGE_EVENT_2)).toBe(MESSAGE_EVENT_2);
222+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(null);
223+
expect(eventProcessor(MESSAGE_EVENT_2, {})).toBe(MESSAGE_EVENT_2);
224224
});
225225

226226
it('prefers message when both message and exception are available', () => {
@@ -231,42 +231,42 @@ describe('InboundFilters', () => {
231231
...EXCEPTION_EVENT,
232232
...MESSAGE_EVENT,
233233
};
234-
expect(eventProcessor(event)).toBe(null);
234+
expect(eventProcessor(event, {})).toBe(null);
235235
});
236236

237237
it('can use multiple filters', () => {
238238
const eventProcessor = createInboundFiltersEventProcessor({
239239
ignoreErrors: ['captureMessage', /SyntaxError/],
240240
});
241-
expect(eventProcessor(MESSAGE_EVENT)).toBe(null);
242-
expect(eventProcessor(EXCEPTION_EVENT)).toBe(null);
241+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(null);
242+
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null);
243243
});
244244

245245
it('uses default filters', () => {
246246
const eventProcessor = createInboundFiltersEventProcessor();
247-
expect(eventProcessor(SCRIPT_ERROR_EVENT)).toBe(null);
247+
expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null);
248248
});
249249

250250
describe('on exception', () => {
251251
it('uses exception data when message is unavailable', () => {
252252
const eventProcessor = createInboundFiltersEventProcessor({
253253
ignoreErrors: ['SyntaxError: unidentified ? at line 1337'],
254254
});
255-
expect(eventProcessor(EXCEPTION_EVENT)).toBe(null);
255+
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null);
256256
});
257257

258258
it('can match on exception value', () => {
259259
const eventProcessor = createInboundFiltersEventProcessor({
260260
ignoreErrors: [/unidentified \?/],
261261
});
262-
expect(eventProcessor(EXCEPTION_EVENT)).toBe(null);
262+
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null);
263263
});
264264

265265
it('can match on exception type', () => {
266266
const eventProcessor = createInboundFiltersEventProcessor({
267267
ignoreErrors: [/^SyntaxError/],
268268
});
269-
expect(eventProcessor(EXCEPTION_EVENT)).toBe(null);
269+
expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null);
270270
});
271271
});
272272
});
@@ -276,78 +276,78 @@ describe('InboundFilters', () => {
276276
const eventProcessorDeny = createInboundFiltersEventProcessor({
277277
denyUrls: ['https://awesome-analytics.io'],
278278
});
279-
expect(eventProcessorDeny(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
279+
expect(eventProcessorDeny(MESSAGE_EVENT_WITH_STACKTRACE, {})).toBe(null);
280280
});
281281

282282
it('should allow denyUrls to take precedence', () => {
283283
const eventProcessorBoth = createInboundFiltersEventProcessor({
284284
allowUrls: ['https://awesome-analytics.io'],
285285
denyUrls: ['https://awesome-analytics.io'],
286286
});
287-
expect(eventProcessorBoth(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
287+
expect(eventProcessorBoth(MESSAGE_EVENT_WITH_STACKTRACE, {})).toBe(null);
288288
});
289289

290290
it('should filter captured message based on its stack trace using regexp filter', () => {
291291
const eventProcessorDeny = createInboundFiltersEventProcessor({
292292
denyUrls: [/awesome-analytics\.io/],
293293
});
294-
expect(eventProcessorDeny(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
294+
expect(eventProcessorDeny(MESSAGE_EVENT_WITH_STACKTRACE, {})).toBe(null);
295295
});
296296

297297
it('should not filter captured messages with no stacktraces', () => {
298298
const eventProcessor = createInboundFiltersEventProcessor({
299299
denyUrls: ['https://awesome-analytics.io'],
300300
});
301-
expect(eventProcessor(MESSAGE_EVENT)).toBe(MESSAGE_EVENT);
301+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(MESSAGE_EVENT);
302302
});
303303

304304
it('should filter captured exception based on its stack trace using string filter', () => {
305305
const eventProcessor = createInboundFiltersEventProcessor({
306306
denyUrls: ['https://awesome-analytics.io'],
307307
});
308-
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES)).toBe(null);
308+
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES, {})).toBe(null);
309309
});
310310

311311
it('should filter captured exception based on its stack trace using regexp filter', () => {
312312
const eventProcessor = createInboundFiltersEventProcessor({
313313
denyUrls: [/awesome-analytics\.io/],
314314
});
315-
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES)).toBe(null);
315+
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES, {})).toBe(null);
316316
});
317317

318318
it("should not filter events that don't match the filtered values", () => {
319319
const eventProcessor = createInboundFiltersEventProcessor({
320320
denyUrls: ['some-other-domain.com'],
321321
});
322-
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES)).toBe(EXCEPTION_EVENT_WITH_FRAMES);
322+
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES, {})).toBe(EXCEPTION_EVENT_WITH_FRAMES);
323323
});
324324

325325
it('should be able to use multiple filters', () => {
326326
const eventProcessor = createInboundFiltersEventProcessor({
327327
denyUrls: ['some-other-domain.com', /awesome-analytics\.io/],
328328
});
329-
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES)).toBe(null);
329+
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES, {})).toBe(null);
330330
});
331331

332332
it('should not fail with malformed event event', () => {
333333
const eventProcessor = createInboundFiltersEventProcessor({
334334
denyUrls: ['https://awesome-analytics.io'],
335335
});
336-
expect(eventProcessor(MALFORMED_EVENT)).toBe(MALFORMED_EVENT);
336+
expect(eventProcessor(MALFORMED_EVENT, {})).toBe(MALFORMED_EVENT);
337337
});
338338

339339
it('should search for script names when there is an anonymous callback at the last frame', () => {
340340
const eventProcessor = createInboundFiltersEventProcessor({
341341
denyUrls: ['https://awesome-analytics.io/some/file.js'],
342342
});
343-
expect(eventProcessor(MESSAGE_EVENT_WITH_ANON_LAST_FRAME)).toBe(null);
343+
expect(eventProcessor(MESSAGE_EVENT_WITH_ANON_LAST_FRAME, {})).toBe(null);
344344
});
345345

346346
it('should search for script names when the last frame is from native code', () => {
347347
const eventProcessor = createInboundFiltersEventProcessor({
348348
denyUrls: ['https://awesome-analytics.io/some/file.js'],
349349
});
350-
expect(eventProcessor(MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME)).toBe(null);
350+
expect(eventProcessor(MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME, {})).toBe(null);
351351
});
352352
});
353353
});

packages/hub/src/scope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export class Scope implements ScopeInterface {
436436
* @param hint May contain additional information about the original exception.
437437
* @hidden
438438
*/
439-
public applyToEvent(event: Event, hint?: EventHint): PromiseLike<Event | null> {
439+
public applyToEvent(event: Event, hint: EventHint = {}): PromiseLike<Event | null> {
440440
if (this._extra && Object.keys(this._extra).length) {
441441
event.extra = { ...this._extra, ...event.extra };
442442
}
@@ -491,7 +491,7 @@ export class Scope implements ScopeInterface {
491491
protected _notifyEventProcessors(
492492
processors: EventProcessor[],
493493
event: Event | null,
494-
hint?: EventHint,
494+
hint: EventHint,
495495
index: number = 0,
496496
): PromiseLike<Event | null> {
497497
return new SyncPromise<Event | null>((resolve, reject) => {

packages/integrations/src/debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Debug implements Integration {
3737
* @inheritDoc
3838
*/
3939
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
40-
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
40+
addGlobalEventProcessor((event: Event, hint: EventHint) => {
4141
const self = getCurrentHub().getIntegration(Debug);
4242
if (self) {
4343
if (self._options.debugger) {
@@ -49,12 +49,12 @@ export class Debug implements Integration {
4949
consoleSandbox(() => {
5050
if (self._options.stringify) {
5151
console.log(JSON.stringify(event, null, 2));
52-
if (hint) {
52+
if (Object.keys(hint).length) {
5353
console.log(JSON.stringify(hint, null, 2));
5454
}
5555
} else {
5656
console.log(event);
57-
if (hint) {
57+
if (Object.keys(hint).length) {
5858
console.log(hint);
5959
}
6060
}

packages/integrations/src/extraerrordata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ExtraErrorData implements Integration {
3737
* @inheritDoc
3838
*/
3939
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
40-
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
40+
addGlobalEventProcessor((event: Event, hint: EventHint) => {
4141
const self = getCurrentHub().getIntegration(ExtraErrorData);
4242
if (!self) {
4343
return event;
@@ -49,8 +49,8 @@ export class ExtraErrorData implements Integration {
4949
/**
5050
* Attaches extracted information from the Error object to extra field in the Event
5151
*/
52-
public enhanceEventWithErrorData(event: Event, hint?: EventHint): Event {
53-
if (!hint || !hint.originalException || !isError(hint.originalException)) {
52+
public enhanceEventWithErrorData(event: Event, hint: EventHint = {}): Event {
53+
if (!hint.originalException || !isError(hint.originalException)) {
5454
return event;
5555
}
5656
const exceptionName = (hint.originalException as ExtendedError).name || hint.originalException.constructor.name;

packages/integrations/test/debug.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Debug integration setup should register an event processor that', () =
2727

2828
const captureEventProcessor = (eventProcessor: EventProcessor) => {
2929
const testEvent = { event_id: 'some event' };
30-
void eventProcessor(testEvent);
30+
void eventProcessor(testEvent, {});
3131
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
3232
expect(mockConsoleLog).toBeCalledWith(testEvent);
3333
};
@@ -55,7 +55,7 @@ describe('Debug integration setup should register an event processor that', () =
5555

5656
const captureEventProcessor = (eventProcessor: EventProcessor) => {
5757
const testEvent = { event_id: 'some event' };
58-
void eventProcessor(testEvent);
58+
void eventProcessor(testEvent, {});
5959
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
6060
expect(mockConsoleLog).toBeCalledWith(JSON.stringify(testEvent, null, 2));
6161
};

packages/integrations/test/offline.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function processEventListeners(): void {
202202
function processEvents(): void {
203203
eventProcessors.forEach(processor => {
204204
events.forEach(event => {
205-
processor(event) as Event | null;
205+
processor(event, {}) as Event | null;
206206
});
207207
});
208208
}

packages/node/src/integrations/linkederrors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class LinkedErrors implements Integration {
4343
* @inheritDoc
4444
*/
4545
public setupOnce(): void {
46-
addGlobalEventProcessor(async (event: Event, hint?: EventHint) => {
46+
addGlobalEventProcessor(async (event: Event, hint: EventHint) => {
4747
const hub = getCurrentHub();
4848
const self = hub.getIntegration(LinkedErrors);
4949
const client = hub.getClient<NodeClient>();
@@ -57,8 +57,8 @@ export class LinkedErrors implements Integration {
5757
/**
5858
* @inheritDoc
5959
*/
60-
private _handler(stackParser: StackParser, event: Event, hint?: EventHint): PromiseLike<Event> {
61-
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
60+
private _handler(stackParser: StackParser, event: Event, hint: EventHint): PromiseLike<Event> {
61+
if (!event.exception || !event.exception.values || !isInstanceOf(hint.originalException, Error)) {
6262
return resolvedSyncPromise(event);
6363
}
6464

packages/node/test/integrations/linkederrors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('LinkedErrors', () => {
1919
const event = {
2020
message: 'foo',
2121
};
22-
return linkedErrors._handler(stackParser, event).then((result: any) => {
22+
return linkedErrors._handler(stackParser, event, {}).then((result: any) => {
2323
expect(spy.mock.calls.length).toEqual(0);
2424
expect(result).toEqual(event);
2525
});
@@ -36,7 +36,7 @@ describe('LinkedErrors', () => {
3636
.eventFromException(one)
3737
.then(eventFromException => {
3838
event = eventFromException;
39-
return linkedErrors._handler(stackParser, eventFromException);
39+
return linkedErrors._handler(stackParser, eventFromException, {});
4040
})
4141
.then(result => {
4242
expect(spy.mock.calls.length).toEqual(0);

packages/types/src/eventprocessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import { Event, EventHint } from './event';
88
*/
99
export interface EventProcessor {
1010
id?: string; // This field can't be named "name" because functions already have this field natively
11-
(event: Event, hint?: EventHint): PromiseLike<Event | null> | Event | null;
11+
(event: Event, hint: EventHint): PromiseLike<Event | null> | Event | null;
1212
}

packages/types/src/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
191191
* @param hint May contain additional information about the original exception.
192192
* @returns A new event that will be sent | null.
193193
*/
194-
beforeSend?: (event: Event, hint?: EventHint) => PromiseLike<Event | null> | Event | null;
194+
beforeSend?: (event: Event, hint: EventHint) => PromiseLike<Event | null> | Event | null;
195195

196196
/**
197197
* A callback invoked when adding a breadcrumb, allowing to optionally modify

0 commit comments

Comments
 (0)