Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export { buildElementSelector } from './utils/selector';
export { EventRejectedError } from './errors';
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
export type { BreadcrumbStore, BreadcrumbsAPI, BreadcrumbHint, BreadcrumbInput } from './breadcrumbs/breadcrumb-store';
export type { MessageHint, MessageProcessor, ProcessingPayload } from './messages/message-processor';
export { BreadcrumbsMessageProcessor } from './messages/breadcrumbs-message-processor';;
24 changes: 24 additions & 0 deletions packages/core/src/messages/breadcrumbs-message-processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { MessageHint, MessageProcessor, ProcessingPayload } from './message-processor';

/**
* Attaches breadcrumbs snapshot from {@link hint} to payload.
*/
export class BreadcrumbsMessageProcessor implements MessageProcessor<'errors/javascript'> {
/**
* Sets `payload.breadcrumbs` from hint snapshot if non-empty; skips otherwise.
*
* @param payload - event message payload to enrich
* @param hint - hint carrying breadcrumbs snapshot captured at error time
* @returns modified payload with breadcrumbs set, or original payload unchanged

Check warning on line 12 in packages/core/src/messages/breadcrumbs-message-processor.ts

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns type
*/
public apply(
payload: ProcessingPayload<'errors/javascript'>,
hint?: MessageHint
): ProcessingPayload<'errors/javascript'> | null {
if (hint?.breadcrumbs && hint.breadcrumbs.length > 0) {
payload.breadcrumbs = hint.breadcrumbs;
}

return payload;
}
}
57 changes: 57 additions & 0 deletions packages/core/src/messages/message-processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Breadcrumb, CatcherMessagePayload, CatcherMessageType } from '@hawk.so/types';

/**
* Extracted addons type from catcher message payload.
*
* @typeParam T - catcher message type

Check warning on line 6 in packages/core/src/messages/message-processor.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid JSDoc tag name "typeParam"
*/
type ExtractAddons<T extends CatcherMessageType> =
CatcherMessagePayload<T> extends { addons?: infer A } ? A : never;

/**
* Payload type used during message processing pipeline.
*
* Same as {@link CatcherMessagePayload} but with `addons` always defined and partially filled —
* processors may contribute individual addon fields independently of each other.
*
* @typeParam T - catcher message type this payload belongs to

Check warning on line 17 in packages/core/src/messages/message-processor.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid JSDoc tag name "typeParam"
*/
export type ProcessingPayload<T extends CatcherMessageType> =
Omit<CatcherMessagePayload<T>, 'addons'> & {
addons: Partial<ExtractAddons<T>>;
};

/**
* Snapshot of event context captured synchronously at error time,
* before any processing.
*/
export interface MessageHint {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Term "hint" is not clear, let's find a better alternative

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can suggest one of

  • MessageContext
  • EventContext
  • ErrorContext
  • MessageSnapshot
  • EventSnapshot
  • ErrorSnapshot

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ErrorSnapshot is more suitable

  • *Context confuses since we already have EventContext
  • it literally contains some snapshot of breadcrumbs and original error

/**
* Original caught error.
*/
error?: Error | string;

/**
* Breadcrumbs captured at error time.
*/
breadcrumbs?: Breadcrumb[];
}

/**
* Single step in message processing pipeline before message is sent.
*
* @typeParam T - catcher message type this processor handles

Check warning on line 43 in packages/core/src/messages/message-processor.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid JSDoc tag name "typeParam"
*/
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
/**
* Handles input message. May mutate or replace it.
*
* @param payload - processed event message payload with partially-built addons
* @param hint - additional context about original error
* @returns modified payload, or `null` to drop event
*/
apply(
payload: ProcessingPayload<T>,
hint?: MessageHint,
): ProcessingPayload<T> | null
}
1 change: 0 additions & 1 deletion packages/core/src/modules/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
private static readonly maxArrayLength: number = 10;

/**
* Custom type handlers registered via {@link registerHandler}.

Check warning on line 52 in packages/core/src/modules/sanitizer.ts

View workflow job for this annotation

GitHub Actions / lint

The type 'sanitize' is undefined

Check warning on line 52 in packages/core/src/modules/sanitizer.ts

View workflow job for this annotation

GitHub Actions / lint

The type 'registerHandler' is undefined
*
* Checked in {@link sanitize} before built-in type checks.
*/
Expand Down Expand Up @@ -154,7 +154,6 @@
depth: number,
seen: WeakSet<object>
): Record<string, any> | '<deep object>' | '<big object>' {

// If the maximum depth is reached, return a placeholder
if (depth > Sanitizer.maxDepth) {
return '<deep object>';
Expand Down
17 changes: 0 additions & 17 deletions packages/javascript/src/addons/userAgentInfo.ts

This file was deleted.

Loading
Loading