Skip to content

Commit 19c86a4

Browse files
committed
fixes
1 parent cac0b5b commit 19c86a4

File tree

6 files changed

+34
-39
lines changed

6 files changed

+34
-39
lines changed

Diff for: packages/core/src/client.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,27 @@ interface DoNotSendEventError {
8181
[DO_NOT_SEND_EVENT_SYMBOL]: true;
8282
}
8383

84-
function makeInternalError(message: string): InternalError {
84+
/** Exported for tests only. */
85+
export function _makeInternalError(message: string): InternalError {
8586
return {
8687
message,
8788
[INTERNAL_ERROR_SYMBOL]: true,
8889
};
8990
}
9091

91-
function makeDoNotSendEventError(message: string): DoNotSendEventError {
92+
/** Exported for tests only. */
93+
export function _makeDoNotSendEventError(message: string): DoNotSendEventError {
9294
return {
9395
message,
9496
[DO_NOT_SEND_EVENT_SYMBOL]: true,
9597
};
9698
}
9799

98-
function isInternalError(error: unknown): error is InternalError {
100+
function _isInternalError(error: unknown): error is InternalError {
99101
return !!error && typeof error === 'object' && INTERNAL_ERROR_SYMBOL in error;
100102
}
101103

102-
function isDoNotSendEventError(error: unknown): error is DoNotSendEventError {
104+
function _isDoNotSendEventError(error: unknown): error is DoNotSendEventError {
103105
return !!error && typeof error === 'object' && DO_NOT_SEND_EVENT_SYMBOL in error;
104106
}
105107

@@ -1009,9 +1011,9 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10091011
},
10101012
reason => {
10111013
if (DEBUG_BUILD) {
1012-
if (isDoNotSendEventError(reason)) {
1014+
if (_isDoNotSendEventError(reason)) {
10131015
logger.log(reason.message);
1014-
} else if (isInternalError(reason)) {
1016+
} else if (_isInternalError(reason)) {
10151017
logger.warn(reason.message);
10161018
} else {
10171019
logger.warn(reason);
@@ -1056,7 +1058,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10561058
if (isError && typeof parsedSampleRate === 'number' && Math.random() > parsedSampleRate) {
10571059
this.recordDroppedEvent('sample_rate', 'error');
10581060
return rejectedSyncPromise(
1059-
makeDoNotSendEventError(
1061+
_makeDoNotSendEventError(
10601062
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
10611063
),
10621064
);
@@ -1068,7 +1070,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10681070
.then(prepared => {
10691071
if (prepared === null) {
10701072
this.recordDroppedEvent('event_processor', dataCategory);
1071-
throw makeDoNotSendEventError('An event processor returned `null`, will not send event.');
1073+
throw _makeDoNotSendEventError('An event processor returned `null`, will not send event.');
10721074
}
10731075

10741076
const isInternalException = hint.data && (hint.data as { __sentry__: boolean }).__sentry__ === true;
@@ -1088,7 +1090,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
10881090
const spanCount = 1 + spans.length;
10891091
this.recordDroppedEvent('before_send', 'span', spanCount);
10901092
}
1091-
throw makeDoNotSendEventError(`${beforeSendLabel} returned \`null\`, will not send event.`);
1093+
throw _makeDoNotSendEventError(`${beforeSendLabel} returned \`null\`, will not send event.`);
10921094
}
10931095

10941096
const session = currentScope.getSession() || isolationScope.getSession();
@@ -1122,7 +1124,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
11221124
return processedEvent;
11231125
})
11241126
.then(null, reason => {
1125-
if (isDoNotSendEventError(reason) || isInternalError(reason)) {
1127+
if (_isDoNotSendEventError(reason) || _isInternalError(reason)) {
11261128
throw reason;
11271129
}
11281130

@@ -1132,7 +1134,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
11321134
},
11331135
originalException: reason,
11341136
});
1135-
throw makeInternalError(
1137+
throw _makeInternalError(
11361138
`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${reason}`,
11371139
);
11381140
});
@@ -1237,17 +1239,17 @@ function _validateBeforeSendResult(
12371239
if (isThenable(beforeSendResult)) {
12381240
return beforeSendResult.then(
12391241
event => {
1240-
if (!isPlainObject(event) && event) {
1241-
throw makeInternalError(invalidValueError);
1242+
if (!isPlainObject(event) && event !== null) {
1243+
throw _makeInternalError(invalidValueError);
12421244
}
12431245
return event;
12441246
},
12451247
e => {
1246-
throw makeInternalError(`${beforeSendLabel} rejected with ${e}`);
1248+
throw _makeInternalError(`${beforeSendLabel} rejected with ${e}`);
12471249
},
12481250
);
1249-
} else if (!isPlainObject(beforeSendResult) && beforeSendResult) {
1250-
throw makeInternalError(invalidValueError);
1251+
} else if (!isPlainObject(beforeSendResult) && beforeSendResult !== null) {
1252+
throw _makeInternalError(invalidValueError);
12511253
}
12521254
return beforeSendResult;
12531255
}

Diff for: packages/core/src/utils-hoist/error.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { ConsoleLevel } from '../types-hoist';
22

3-
/** An error emitted by Sentry SDKs and related utilities. */
3+
/**
4+
* An error emitted by Sentry SDKs and related utilities.
5+
* @deprecated This class is no longer used and will be removed in a future version. Use `Error` instead.
6+
*/
47
export class SentryError extends Error {
58
public logLevel: ConsoleLevel;
69

Diff for: packages/core/src/utils-hoist/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export { applyAggregateErrorsToEvent } from './aggregate-errors';
22
export { getBreadcrumbLogLevelFromHttpStatusCode } from './breadcrumb-log-level';
33
export { getComponentName, getLocationHref, htmlTreeAsString } from './browser';
44
export { dsnFromString, dsnToString, makeDsn } from './dsn';
5+
// eslint-disable-next-line deprecation/deprecation
56
export { SentryError } from './error';
67
export { GLOBAL_OBJ } from './worldwide';
78
export type { InternalGlobal } from './worldwide';

Diff for: packages/core/test/lib/client.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest';
22
import {
33
Scope,
4-
SentryError,
54
SyncPromise,
65
addBreadcrumb,
76
dsnToString,
@@ -13,6 +12,7 @@ import {
1312
withMonitor,
1413
} from '../../src';
1514
import type { BaseClient, Client } from '../../src/client';
15+
import { _makeInternalError } from '../../src/client';
1616
import * as integrationModule from '../../src/integration';
1717
import type { Envelope, ErrorEvent, Event, SpanJSON, TransactionEvent } from '../../src/types-hoist';
1818
import * as loggerModule from '../../src/utils-hoist/logger';
@@ -533,7 +533,7 @@ describe('Client', () => {
533533
);
534534
});
535535

536-
test('it adds a trace context to all events xxx', () => {
536+
test('it adds a trace context to all events', () => {
537537
expect.assertions(1);
538538

539539
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
@@ -1206,7 +1206,7 @@ describe('Client', () => {
12061206
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, beforeSend });
12071207
const client = new TestClient(options);
12081208
const captureExceptionSpy = vi.spyOn(client, 'captureException');
1209-
const loggerWarnSpy = vi.spyOn(loggerModule.logger, 'log');
1209+
const loggerLogSpy = vi.spyOn(loggerModule.logger, 'log');
12101210

12111211
client.captureEvent({ message: 'hello' });
12121212

@@ -1215,7 +1215,7 @@ describe('Client', () => {
12151215
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
12161216
// error, but because `beforeSend` returned `null`
12171217
expect(captureExceptionSpy).not.toBeCalled();
1218-
expect(loggerWarnSpy).toBeCalledWith('before send for type `error` returned `null`, will not send event.');
1218+
expect(loggerLogSpy).toBeCalledWith('before send for type `error` returned `null`, will not send event.');
12191219
});
12201220

12211221
test('calls `beforeSendTransaction` and discards the event', () => {
@@ -1225,7 +1225,7 @@ describe('Client', () => {
12251225
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, beforeSendTransaction });
12261226
const client = new TestClient(options);
12271227
const captureExceptionSpy = vi.spyOn(client, 'captureException');
1228-
const loggerWarnSpy = vi.spyOn(loggerModule.logger, 'log');
1228+
const loggerLogSpy = vi.spyOn(loggerModule.logger, 'log');
12291229

12301230
client.captureEvent({ transaction: '/dogs/are/great', type: 'transaction' });
12311231

@@ -1234,7 +1234,7 @@ describe('Client', () => {
12341234
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
12351235
// error, but because `beforeSendTransaction` returned `null`
12361236
expect(captureExceptionSpy).not.toBeCalled();
1237-
expect(loggerWarnSpy).toBeCalledWith('before send for type `transaction` returned `null`, will not send event.');
1237+
expect(loggerLogSpy).toBeCalledWith('before send for type `transaction` returned `null`, will not send event.');
12381238
});
12391239

12401240
test('does not discard span and warn when returning null from `beforeSendSpan', () => {
@@ -1294,7 +1294,7 @@ describe('Client', () => {
12941294
expect(beforeSend).toHaveBeenCalled();
12951295
expect(TestClient.instance!.event).toBeUndefined();
12961296
expect(loggerWarnSpy).toBeCalledWith(
1297-
new SentryError('before send for type `error` must return `null` or a valid event.'),
1297+
_makeInternalError('before send for type `error` must return `null` or a valid event.').message,
12981298
);
12991299
}
13001300
});
@@ -1315,7 +1315,7 @@ describe('Client', () => {
13151315
expect(beforeSendTransaction).toHaveBeenCalled();
13161316
expect(TestClient.instance!.event).toBeUndefined();
13171317
expect(loggerWarnSpy).toBeCalledWith(
1318-
new SentryError('before send for type `transaction` must return `null` or a valid event.'),
1318+
_makeInternalError('before send for type `transaction` must return `null` or a valid event.').message,
13191319
);
13201320
}
13211321
});
@@ -1688,9 +1688,9 @@ describe('Client', () => {
16881688
originalException: exception,
16891689
});
16901690
expect(loggerWarnSpy).toBeCalledWith(
1691-
new SentryError(
1691+
_makeInternalError(
16921692
`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${exception}`,
1693-
),
1693+
).message,
16941694
);
16951695
});
16961696

Diff for: packages/core/test/utils-hoist/is.test.ts

-11
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ import { supportsDOMError, supportsDOMException, supportsErrorEvent } from '../.
1414
import { resolvedSyncPromise } from '../../src/utils-hoist/syncpromise';
1515
import { testOnlyIfNodeVersionAtLeast } from './testutils';
1616

17-
class SentryError extends Error {
18-
public name: string;
19-
20-
public constructor(public message: string) {
21-
super(message);
22-
this.name = new.target.prototype.constructor.name;
23-
Object.setPrototypeOf(this, new.target.prototype);
24-
}
25-
}
26-
2717
if (supportsDOMError()) {
2818
describe('isDOMError()', () => {
2919
test('should work as advertised', () => {
@@ -47,7 +37,6 @@ describe('isError()', () => {
4737
test('should work as advertised', () => {
4838
expect(isError(new Error())).toEqual(true);
4939
expect(isError(new ReferenceError())).toEqual(true);
50-
expect(isError(new SentryError('message'))).toEqual(true);
5140
expect(isError({})).toEqual(false);
5241
expect(
5342
isError({

Diff for: packages/opentelemetry/test/utils/mapStatus.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('mapStatus', () => {
8181
expect(actual).toEqual(expected);
8282
});
8383

84-
it('works with string SEMATTRS_HTTP_STATUS_CODE xxx', () => {
84+
it('works with string SEMATTRS_HTTP_STATUS_CODE', () => {
8585
const span = createSpan('test-span');
8686

8787
span.setStatus({ code: 0 }); // UNSET

0 commit comments

Comments
 (0)