Skip to content

Commit cd3d297

Browse files
committed
[v7] Random unimportant TODO fixes
1 parent 69d57da commit cd3d297

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

packages/core/src/baseclient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Integration,
1111
TransportRequest,
1212
Transport,
13+
EventType,
1314
} from '@sentry/types';
1415
import {
1516
dateTimestampInSeconds,
@@ -388,7 +389,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
388389
}
389390

390391
// TODO: Make it configurable or move to @sentry/integration-browser-breadcrumbs
391-
const eventType = processedEvent.type === 'transaction' ? 'transaction' : 'event';
392+
const eventType = processedEvent.type === EventType.Transaction ? 'transaction' : 'event';
392393
this.getScope().addBreadcrumb(
393394
{
394395
category: `sentry.${eventType}`,

packages/eventbuilder-node/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
import { extractStackFromError, parseError, parseStack, prepareFramesForEvent } from './parsers';
1414
export { getExceptionFromError } from './parsers';
1515

16-
export function eventFromException(options: Options, exception: unknown, captureContext: CaptureContext): SentryEvent {
16+
export function eventFromException(
17+
options: Options & { serverName?: string },
18+
exception: unknown,
19+
captureContext: CaptureContext,
20+
): SentryEvent {
1721
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1822
let ex: any = exception;
1923
const mechanism: Mechanism = {
@@ -46,9 +50,8 @@ export function eventFromException(options: Options, exception: unknown, capture
4650
event.event_id = captureContext.hint?.event_id;
4751
}
4852
event.platform = 'node';
49-
// TODO: Fix options type - we dont want to have a circular dependency on @sentry/node here
50-
if ((options as { serverName?: string }).serverName) {
51-
event.server_name = (options as { serverName?: string }).serverName;
53+
if (options.serverName) {
54+
event.server_name = options.serverName;
5255
}
5356
if (shouldSerializeException) {
5457
event.extra = event.extra || {};

packages/transport-base/src/transport.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export abstract class BaseTransport {
5656
return this._asyncBuffer.add(sendRequestTask);
5757
}
5858

59-
// TODO: Make requestMaker an abstract method that has to be implemented by the class that extends it?
6059
public flush(timeout: number = 0): PromiseLike<boolean> {
6160
return this._asyncBuffer.drain(timeout);
6261
}

packages/types/src/mechanism.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export interface Mechanism {
2-
type: string;
3-
handled: boolean;
4-
data?: {
5-
[key: string]: string | boolean;
6-
};
2+
[key: string]: unknown;
3+
type?: string;
4+
handled?: boolean;
75
synthetic?: boolean;
6+
data?: Record<string, unknown>;
87
}

packages/utils/src/misc.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { SentryEvent, SentryGlobal, WrappedFunction } from '@sentry/types';
2+
import { Mechanism, SentryEvent, SentryGlobal, WrappedFunction } from '@sentry/types';
33

44
import { isNodeEnv } from './node';
55

@@ -182,22 +182,19 @@ export function addExceptionTypeValue(event: SentryEvent, value?: string, type?:
182182
* @param mechanism Mechanism of the mechanism.
183183
* @hidden
184184
*/
185-
export function addExceptionMechanism(
186-
event: SentryEvent,
187-
mechanism: {
188-
[key: string]: any;
189-
} = {},
190-
): void {
191-
// TODO: Use real type with `keyof Mechanism` thingy and maybe make it better?
185+
export function addExceptionMechanism(event: SentryEvent, mechanism: Mechanism): void {
192186
try {
193-
// @ts-ignore Type 'Mechanism | {}' is not assignable to type 'Mechanism | undefined'
194-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
195-
event.exception!.values![0].mechanism = event.exception!.values![0].mechanism || {};
196-
Object.keys(mechanism).forEach(key => {
197-
// @ts-ignore Mechanism has no index signature
198-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
199-
event.exception!.values![0].mechanism[key] = mechanism[key];
200-
});
187+
const exception = event.exception?.values?.[0];
188+
189+
if (exception) {
190+
exception.mechanism = exception.mechanism || {
191+
type: mechanism.type,
192+
};
193+
194+
for (const [key, value] of Object.entries(mechanism)) {
195+
exception.mechanism[key] = value;
196+
}
197+
}
201198
} catch (_oO) {
202199
// no-empty
203200
}

0 commit comments

Comments
 (0)