Skip to content

Commit de681dc

Browse files
authored
feat(v8): Update eventFromUnknownInput to only use client (#10692)
ref #10100
1 parent 3e2c8f4 commit de681dc

File tree

5 files changed

+14
-79
lines changed

5 files changed

+14
-79
lines changed

packages/core/src/server-runtime-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { eventFromMessage, eventFromUnknownInput, logger, resolvedSyncPromise, u
1515

1616
import { BaseClient } from './baseclient';
1717
import { createCheckInEnvelope } from './checkin';
18-
import { getClient, getIsolationScope } from './currentScopes';
18+
import { getIsolationScope } from './currentScopes';
1919
import { DEBUG_BUILD } from './debug-build';
2020
import type { Scope } from './scope';
2121
import { SessionFlusher } from './sessionflusher';
@@ -56,7 +56,7 @@ export class ServerRuntimeClient<
5656
* @inheritDoc
5757
*/
5858
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
59-
return resolvedSyncPromise(eventFromUnknownInput(getClient(), this._options.stackParser, exception, hint));
59+
return resolvedSyncPromise(eventFromUnknownInput(this, this._options.stackParser, exception, hint));
6060
}
6161

6262
/**

packages/deno/src/integrations/globalhandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function installGlobalErrorHandler(client: Client): void {
6767

6868
const { message, error } = data;
6969

70-
const event = eventFromUnknownInput(getClient(), stackParser, error || message);
70+
const event = eventFromUnknownInput(client, stackParser, error || message);
7171

7272
event.level = 'fatal';
7373

@@ -116,7 +116,7 @@ function installGlobalUnhandledRejectionHandler(client: Client): void {
116116

117117
const event = isPrimitive(error)
118118
? eventFromRejectionWithPrimitive(error)
119-
: eventFromUnknownInput(getClient(), stackParser, error, undefined);
119+
: eventFromUnknownInput(client, stackParser, error, undefined);
120120

121121
event.level = 'fatal';
122122

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Hub } from '@sentry/types';
21
import { eventFromUnknownInput } from '@sentry/utils';
32

43
import { defaultStackParser } from '../src';
@@ -44,50 +43,4 @@ describe('eventFromUnknownInput', () => {
4443
},
4544
});
4645
});
47-
48-
test('uses normalizeDepth from init options (passing getCurrentHub)', () => {
49-
const deepObject = {
50-
a: {
51-
b: {
52-
c: {
53-
d: {
54-
e: {
55-
f: {
56-
g: 'foo',
57-
},
58-
},
59-
},
60-
},
61-
},
62-
},
63-
};
64-
65-
const getCurrentHub = jest.fn(() => {
66-
return {
67-
getClient: () => ({
68-
getOptions(): any {
69-
return { normalizeDepth: 6 };
70-
},
71-
}),
72-
} as unknown as Hub;
73-
});
74-
75-
const event = eventFromUnknownInput(getCurrentHub, defaultStackParser, deepObject);
76-
77-
const serializedObject = event.extra?.__serialized__;
78-
expect(serializedObject).toBeDefined();
79-
expect(serializedObject).toEqual({
80-
a: {
81-
b: {
82-
c: {
83-
d: {
84-
e: {
85-
f: '[Object]',
86-
},
87-
},
88-
},
89-
},
90-
},
91-
});
92-
});
9346
});

packages/utils/src/eventbuilder.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
EventHint,
55
Exception,
66
Extras,
7-
Hub,
87
Mechanism,
98
ParameterizedString,
109
SeverityLevel,
@@ -63,22 +62,14 @@ function getMessageForObject(exception: object): string {
6362

6463
/**
6564
* Builds and Event from a Exception
66-
*
67-
* TODO(v8): Remove getHub fallback
6865
* @hidden
6966
*/
7067
export function eventFromUnknownInput(
71-
getHubOrClient: (() => Hub) | Client | undefined,
68+
client: Client,
7269
stackParser: StackParser,
7370
exception: unknown,
7471
hint?: EventHint,
7572
): Event {
76-
const client =
77-
typeof getHubOrClient === 'function'
78-
? // eslint-disable-next-line deprecation/deprecation
79-
getHubOrClient().getClient()
80-
: getHubOrClient;
81-
8273
let ex: unknown = exception;
8374
const providedMechanism: Mechanism | undefined =
8475
hint && hint.data && (hint.data as { mechanism: Mechanism }).mechanism;
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1-
import type { Hub, Scope } from '@sentry/types';
1+
import type { Client } from '@sentry/types';
22

33
import { createStackParser, eventFromUnknownInput, nodeStackLineParser } from '../src';
44

5-
function getCurrentHub(): Hub {
6-
// Some fake hub to get us through
7-
return {
8-
getClient: () => undefined,
9-
getScope: () => {
10-
return {
11-
setExtra: () => {},
12-
} as unknown as Scope;
13-
},
14-
} as unknown as Hub;
15-
}
16-
175
const stackParser = createStackParser(nodeStackLineParser());
186

197
describe('eventFromUnknownInput', () => {
8+
const fakeClient = {
9+
getOptions: () => ({}),
10+
} as Client;
2011
test('object with useless props', () => {
21-
const event = eventFromUnknownInput(getCurrentHub, stackParser, { foo: { bar: 'baz' }, prop: 1 });
12+
const event = eventFromUnknownInput(fakeClient, stackParser, { foo: { bar: 'baz' }, prop: 1 });
2213
expect(event.exception?.values?.[0].value).toBe('Object captured as exception with keys: foo, prop');
2314
});
2415

2516
test('object with name prop', () => {
26-
const event = eventFromUnknownInput(getCurrentHub, stackParser, { foo: { bar: 'baz' }, name: 'BadType' });
17+
const event = eventFromUnknownInput(fakeClient, stackParser, { foo: { bar: 'baz' }, name: 'BadType' });
2718
expect(event.exception?.values?.[0].value).toBe("'BadType' captured as exception");
2819
});
2920

3021
test('object with name and message props', () => {
31-
const event = eventFromUnknownInput(getCurrentHub, stackParser, { message: 'went wrong', name: 'BadType' });
22+
const event = eventFromUnknownInput(fakeClient, stackParser, { message: 'went wrong', name: 'BadType' });
3223
expect(event.exception?.values?.[0].value).toBe("'BadType' captured as exception with message 'went wrong'");
3324
});
3425

3526
test('object with message prop', () => {
36-
const event = eventFromUnknownInput(getCurrentHub, stackParser, { foo: { bar: 'baz' }, message: 'Some message' });
27+
const event = eventFromUnknownInput(fakeClient, stackParser, { foo: { bar: 'baz' }, message: 'Some message' });
3728
expect(event.exception?.values?.[0].value).toBe('Some message');
3829
});
3930

4031
test('passing client directly', () => {
41-
const event = eventFromUnknownInput(undefined, stackParser, { foo: { bar: 'baz' }, prop: 1 });
32+
const event = eventFromUnknownInput(fakeClient, stackParser, { foo: { bar: 'baz' }, prop: 1 });
4233
expect(event.exception?.values?.[0].value).toBe('Object captured as exception with keys: foo, prop');
4334
});
4435
});

0 commit comments

Comments
 (0)