BaseCatcher abstraction added#161
Conversation
6d66554 to
0ca5710
Compare
79ab0f0 to
dd4f541
Compare
0ca5710 to
4ad2b5f
Compare
dd4f541 to
ee65ab6
Compare
f99d5fe to
173d40e
Compare
1cb3077 to
70d214e
Compare
cc8919a to
f460ea3
Compare
ee65ab6 to
0f9ed18
Compare
0f9ed18 to
fcb3798
Compare
neSpecc
left a comment
There was a problem hiding this comment.
The PR contains changes for other PRs
5b9716d to
4a6adc0
Compare
a02cf33 to
b8c9b5c
Compare
4a6adc0 to
16ca176
Compare
b8c9b5c to
c049bd4
Compare
16ca176 to
465508d
Compare
9248931 to
9e5d66a
Compare
Env-agnostic logic from Catcher in @hawk.so/javascript moved in new abstract BaseCatcher so general logic (breadcrumbs management, user management, context management, message pre-processing and sending, and other utilities) may be reused in other platform-specific implementations. Browser-specific logic (UI-framework integrations, window event listeners, ConsoleCatcher) remain in original Catcher in @hawk.so/javascript.
465508d to
53ed83c
Compare
Should be fixed yet. |
There was a problem hiding this comment.
Pull request overview
This PR extracts environment-agnostic catcher logic from @hawk.so/javascript into a new reusable BaseCatcher in @hawk.so/core, keeping browser-specific behavior in the JavaScript catcher.
Changes:
- Introduced
BaseCatcherin@hawk.so/coreto host shared event pipeline logic (context/user/breadcrumbs/processors/beforeSend/transport dispatch). - Refactored
@hawk.so/javascriptCatcherto extendBaseCatcherand keep browser-only concerns (Socket transport wiring, window handlers, console tracking, breadcrumbs store, performance issues). - Adjusted addon imports and bumped
@hawk.so/javascriptpatch version.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/javascript/src/catcher.ts | Refactors JS Catcher to extend the new core BaseCatcher and wires browser-specific transport/processors/handlers. |
| packages/javascript/src/addons/console-output-addon-message-processor.ts | Fixes relative import path for ConsoleCatcher. |
| packages/javascript/src/addons/browser-breadcrumbs-message-processor.ts | Fixes relative import paths for breadcrumbs types/store. |
| packages/javascript/package.json | Bumps package version to 3.3.2. |
| packages/core/src/index.ts | Exports BaseCatcher and BeforeSendHook from core public API. |
| packages/core/src/catcher.ts | Adds the new BaseCatcher abstraction containing shared catcher logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Each {@link formatAndSend} call initiates **sending pipeline** which consist of following steps: | ||
| * - base payload is built, | ||
| * - sequentially apply message processors to payload | ||
| * - apply optional {@link BeforeSendHook}, | ||
| * - dispatch message via {@link Transport}. |
| /** | ||
| * Process and sends error message. | ||
| * | ||
| * Returns early without sending if: | ||
| * - error was already processed, | ||
| * - a message processor drops it, | ||
| * - {@link beforeSend} hook rejects it. | ||
| * | ||
| * @param error - error to send | ||
| * @param integrationAddons - addons passed by integration (e.g. Vue, Nuxt) | ||
| * @param context - any additional data passed by user | ||
| */ | ||
| protected async formatAndSend( | ||
| error: Error | string, | ||
| integrationAddons?: Record<string, unknown>, | ||
| context?: EventContext | ||
| ): Promise<void> { | ||
| try { | ||
| if (isErrorProcessed(error)) { | ||
| return; | ||
| } | ||
|
|
||
| markErrorAsProcessed(error); | ||
|
|
||
| let processingPayload = await this.buildBasePayload(error, context); | ||
|
|
||
| for (const processor of this.messageProcessors) { | ||
| const result = processor.apply(processingPayload, error); | ||
|
|
||
| if (result === null) { | ||
| // Event was rejected by user using the beforeSend method | ||
| return; | ||
| } | ||
|
|
||
| processingPayload = result; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const payload = processingPayload as any as CatcherMessagePayload<T>; | ||
|
|
||
| if (integrationAddons) { | ||
| payload.addons = { | ||
| ...(payload.addons ?? {}), | ||
| ...Sanitizer.sanitize(integrationAddons), | ||
| }; | ||
| } | ||
|
|
||
| const filtered = this.applyBeforeSendHook(payload); | ||
|
|
||
| if (filtered === null) { | ||
| return; | ||
| } | ||
|
|
||
| this.sendMessage({ | ||
| token: this.token, | ||
| catcherType: this.getCatcherType(), | ||
| payload: filtered, | ||
| } as CatcherMessage<T>); | ||
| } catch (e) { | ||
| 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); | ||
| } | ||
| } |
| */ | ||
| public test(): void { | ||
| const fakeEvent = new Error('Hawk JavaScript Catcher test message.'); | ||
| private static decodeIntegrationId(token: EncodedIntegrationToken): string { |
There was a problem hiding this comment.
probably also can be reused across browser/node catchers, so could be moved to base catcher or utility.
| // Promise rejection reason is recommended to be an Error, but it can be a string: | ||
| // - Promise.reject(new Error('Reason message')) ——— recommended | ||
| // - Promise.reject('Reason message') |
There was a problem hiding this comment.
use block-style comments please as we do in our code style
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Closes #151
Env-agnostic logic from Catcher in
@hawk.so/javascriptmoved in new abstractBaseCatcherin@hawk.so/coreso general logic (breadcrumbs management, user management, context management, message pre-processing and sending, and other utilities) may be reused in other platform-specific implementations.Browser-specific logic (UI-framework integrations, window event listeners,
ConsoleCatcher) remain in originalCatcherin@hawk.so/javascript.