Skip to content

Commit c3ffcae

Browse files
committed
fix: review fixes
- MessageHint renamed to ErrorSnapshot - minor code style and naming issues fixed
1 parent eba517d commit c3ffcae

6 files changed

Lines changed: 32 additions & 30 deletions

File tree

packages/core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export { buildElementSelector } from './utils/selector';
1313
export { EventRejectedError } from './errors';
1414
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
1515
export type { BreadcrumbStore, BreadcrumbsAPI, BreadcrumbHint, BreadcrumbInput } from './breadcrumbs/breadcrumb-store';
16-
export type { MessageHint, MessageProcessor, ProcessingPayload } from './messages/message-processor';
17-
export { BreadcrumbsMessageProcessor } from './messages/breadcrumbs-message-processor';;
16+
export type { ErrorSnapshot, MessageProcessor, ProcessingPayload } from './messages/message-processor';
17+
export { BreadcrumbsMessageProcessor } from './messages/breadcrumbs-message-processor';

packages/core/src/messages/breadcrumbs-message-processor.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import type { MessageHint, MessageProcessor, ProcessingPayload } from './message-processor';
1+
import type { ErrorSnapshot, MessageProcessor, ProcessingPayload } from './message-processor';
22

33
/**
4-
* Attaches breadcrumbs snapshot from {@link hint} to payload.
4+
* Attaches breadcrumbs to payload.
55
*/
66
export class BreadcrumbsMessageProcessor implements MessageProcessor<'errors/javascript'> {
77
/**
8-
* Sets `payload.breadcrumbs` from hint snapshot if non-empty; skips otherwise.
8+
* Sets `payload.breadcrumbs` from snapshot if non-empty; skips otherwise.
99
*
1010
* @param payload - event message payload to enrich
11-
* @param hint - hint carrying breadcrumbs snapshot captured at error time
11+
* @param snapshot - snapshot carrying breadcrumbs captured at error time
1212
* @returns modified payload with breadcrumbs set, or original payload unchanged
1313
*/
1414
public apply(
1515
payload: ProcessingPayload<'errors/javascript'>,
16-
hint?: MessageHint
16+
snapshot?: ErrorSnapshot
1717
): ProcessingPayload<'errors/javascript'> | null {
18-
if (hint?.breadcrumbs && hint.breadcrumbs.length > 0) {
19-
payload.breadcrumbs = hint.breadcrumbs;
18+
if (snapshot?.breadcrumbs && snapshot.breadcrumbs.length > 0) {
19+
payload.breadcrumbs = snapshot.breadcrumbs;
2020
}
2121

2222
return payload;

packages/core/src/messages/message-processor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type ProcessingPayload<T extends CatcherMessageType> =
2525
* Snapshot of event context captured synchronously at error time,
2626
* before any processing.
2727
*/
28-
export interface MessageHint {
28+
export interface ErrorSnapshot {
2929
/**
3030
* Original caught error.
3131
*/
@@ -47,11 +47,11 @@ export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageT
4747
* Handles input message. May mutate or replace it.
4848
*
4949
* @param payload - processed event message payload with partially-built addons
50-
* @param hint - additional context about original error
50+
* @param snapshot - additional context with original error
5151
* @returns modified payload, or `null` to drop event
5252
*/
5353
apply(
5454
payload: ProcessingPayload<T>,
55-
hint?: MessageHint,
55+
snapshot?: ErrorSnapshot,
5656
): ProcessingPayload<T> | null
5757
}

packages/javascript/src/catcher.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,14 @@ export default class Catcher {
405405
markErrorAsProcessed(error);
406406
}
407407

408-
const hint = { error,
409-
breadcrumbs: this.breadcrumbStore?.get() };
408+
const snapshot = {
409+
error,
410+
breadcrumbs: this.breadcrumbStore?.get()
411+
};
410412
let processingPayload = await this.buildBasePayload(error, context);
411413

412414
for (const processor of this.messageProcessors) {
413-
const result = processor.apply(processingPayload, hint);
415+
const result = processor.apply(processingPayload, snapshot);
414416

415417
if (result === null) {
416418
return;
@@ -428,16 +430,16 @@ export default class Catcher {
428430
};
429431
}
430432

431-
const filtered = this.applyBeforeSendHook(payload);
433+
const payloadPostBeforeSend = this.applyBeforeSendHook(payload);
432434

433-
if (filtered === null) {
435+
if (payloadPostBeforeSend === null) {
434436
return;
435437
}
436438

437439
this.sendMessage({
438440
token: this.token,
439441
catcherType: Catcher.type,
440-
payload: filtered,
442+
payload: payloadPostBeforeSend,
441443
} as CatcherMessage<typeof Catcher.type>);
442444
} catch (e) {
443445
log('Unable to send error. Seems like it is Hawk internal bug. Please, report it here: https://github.com/codex-team/hawk.javascript/issues/new', 'warn', e);

packages/javascript/src/messages/debug-addon-message-processor.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import type { MessageHint, MessageProcessor, ProcessingPayload } from '@hawk.so/core';
1+
import type { ErrorSnapshot, MessageProcessor, ProcessingPayload } from '@hawk.so/core';
22

33
/**
44
* Appends `RAW_EVENT_DATA` to the event addons for debug purposes.
55
*/
66
export class DebugAddonMessageProcessor implements MessageProcessor<'errors/javascript'> {
77
/**
8-
* Writes name, message, and stack from `hint.error` into `payload.addons.RAW_EVENT_DATA`.
9-
* Skips if hint error is not Error instance.
8+
* Writes name, message, and stack from `snapshot.error` into `payload.addons.RAW_EVENT_DATA`.
9+
* Skips if snapshot error is missing or not Error instance.
1010
*
1111
* @param payload - event message payload to enrich
12-
* @param hint - hint carrying original caught error
12+
* @param snapshot - snapshot carrying original caught error
1313
* @returns modified payload with RAW_EVENT_DATA set, or original payload unchanged
1414
*/
1515
public apply(
1616
payload: ProcessingPayload<'errors/javascript'>,
17-
hint?: MessageHint
17+
snapshot?: ErrorSnapshot
1818
): ProcessingPayload<'errors/javascript'> | null {
19-
if (!(hint?.error instanceof Error)) {
19+
if (!(snapshot?.error instanceof Error)) {
2020
return payload;
2121
}
2222

2323
payload.addons.RAW_EVENT_DATA = {
24-
name: hint.error.name,
25-
message: hint.error.message,
26-
stack: hint.error.stack ?? '',
24+
name: snapshot.error.name,
25+
message: snapshot.error.message,
26+
stack: snapshot.error.stack ?? '',
2727
};
2828

2929
return payload;

packages/javascript/tests/messages/breadcrumbs-message-processor.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import { makePayload } from './message-processor.helpers';
55
describe('BreadcrumbsMessageProcessor', () => {
66
const processor = new BreadcrumbsMessageProcessor();
77

8-
it('should attach breadcrumbs from hint to payload', () => {
8+
it('should attach breadcrumbs from snapshot to payload', () => {
99
const breadcrumbs = [{ message: 'click', timestamp: 1 }];
1010

1111
const result = processor.apply(makePayload(), { breadcrumbs });
1212

1313
expect(result?.breadcrumbs).toEqual(breadcrumbs);
1414
});
1515

16-
it('should not set payload breadcrumbs when hint has empty array', () => {
16+
it('should not set payload breadcrumbs when snapshot has empty array', () => {
1717
const result = processor.apply(makePayload(), { breadcrumbs: [] });
1818

1919
expect(result?.breadcrumbs).toBeUndefined();
2020
});
2121

22-
it('should not set payload breadcrumbs when hint is absent', () => {
22+
it('should not set payload breadcrumbs when snapshot is absent', () => {
2323
const result = processor.apply(makePayload());
2424

2525
expect(result?.breadcrumbs).toBeUndefined();

0 commit comments

Comments
 (0)