Skip to content

Commit 3a8de71

Browse files
committed
refactor(javascript): MessageProcessor abstraction added and implemented in catcher event processing pipeline
- MessageProcessor interface and MessageHint type - BrowserMessageProcessor, BreadcrumbsMessageProcessor, ConsoleCatcherMessageProcessor, DebugMessageProcessor - replaced inline addon logic with sequential MessageProcessor pipeline
1 parent 8df48ec commit 3a8de71

14 files changed

+467
-193
lines changed

packages/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +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 } from './messages/message-processor';
17+
export { BreadcrumbsMessageProcessor } from './messages/breadcrumbs-message-processor';;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { CatcherMessagePayload } from '@hawk.so/types';
2+
import { MessageHint, MessageProcessor } from './message-processor';
3+
4+
/**
5+
* Attaches breadcrumbs snapshot from {@link hint} to payload.
6+
*/
7+
export class BreadcrumbsMessageProcessor implements MessageProcessor<'errors/javascript'> {
8+
/**
9+
* Sets `payload.breadcrumbs` from hint snapshot if non-empty; skips otherwise.
10+
*
11+
* @param payload - event message payload to enrich
12+
* @param hint - hint carrying breadcrumbs snapshot captured at error time
13+
* @returns modified payload with breadcrumbs set, or original payload unchanged
14+
*/
15+
apply(
16+
payload: CatcherMessagePayload<'errors/javascript'>,
17+
hint?: MessageHint
18+
): CatcherMessagePayload<'errors/javascript'> | null {
19+
if (hint?.breadcrumbs && hint.breadcrumbs.length > 0) {
20+
payload.breadcrumbs = hint.breadcrumbs;
21+
}
22+
23+
return payload;
24+
}
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { Breadcrumb, CatcherMessagePayload, CatcherMessageType } from '@hawk.so/types';
2+
3+
/**
4+
* Snapshot of event context captured synchronously at error time,
5+
* before any processing.
6+
*/
7+
export interface MessageHint {
8+
/**
9+
* Original caught error.
10+
*/
11+
error?: Error | string;
12+
13+
/**
14+
* Breadcrumbs captured at error time.
15+
*/
16+
breadcrumbs?: Breadcrumb[];
17+
}
18+
19+
/**
20+
* Single step in message processing pipeline before message is sent.
21+
*
22+
* @typeParam T - catcher message type this processor handles
23+
*/
24+
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
25+
/**
26+
* Handles input message. May mutate or replace it.
27+
*
28+
* @param payload - processed event message payload
29+
* @param hint - additional context about original error
30+
* @returns modified payload, or `null` to drop event
31+
*/
32+
apply(
33+
payload: CatcherMessagePayload<T>,
34+
hint?: MessageHint,
35+
): CatcherMessagePayload<T> | null
36+
}

packages/core/src/modules/sanitizer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ export class Sanitizer {
154154
depth: number,
155155
seen: WeakSet<object>
156156
): Record<string, any> | '<deep object>' | '<big object>' {
157-
158157
// If the maximum depth is reached, return a placeholder
159158
if (depth > Sanitizer.maxDepth) {
160159
return '<deep object>';

packages/javascript/src/addons/userAgentInfo.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)