Skip to content

Commit 41ef627

Browse files
committed
clarify and add comments
1 parent 5a25966 commit 41ef627

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

packages/core/test/lib/base.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ describe('BaseClient', () => {
257257
['`Error` instance', new Error('Will I get caught twice?')],
258258
['plain object', { 'Will I': 'get caught twice?' }],
259259
['primitive wrapper', new String('Will I get caught twice?')],
260-
// primitives aren't tested directly here because they need to be wrapped with `objectify` *before* being passed
261-
// to `captureException` (which is how we'd end up with a primitive wrapper as tested above)
260+
// Primitives aren't tested directly here because they need to be wrapped with `objectify` *before* being passed
261+
// to `captureException` (which is how we'd end up with a primitive wrapper as tested above) in order for the
262+
// already-seen check to work . Any primitive which is passed without being wrapped will be captured each time it
263+
// is encountered, so this test doesn't apply.
262264
])("doesn't capture the same exception twice - %s", (_name: string, thrown: any) => {
263265
const client = new TestClient({ dsn: PUBLIC_DSN });
264266

@@ -354,9 +356,14 @@ describe('BaseClient', () => {
354356
['`Error` instance', new Error('Will I get caught twice?')],
355357
['plain object', { 'Will I': 'get caught twice?' }],
356358
['primitive wrapper', new String('Will I get caught twice?')],
357-
// primitives aren't tested directly here because they need to be wrapped with `objectify` *before* being passed
358-
// to `captureEvent` (which is how we'd end up with a primitive wrapper as tested above)
359+
// Primitives aren't tested directly here because they need to be wrapped with `objectify` *before* being passed
360+
// to `captureEvent` (which is how we'd end up with a primitive wrapper as tested above) in order for the
361+
// already-seen check to work . Any primitive which is passed without being wrapped will be captured each time it
362+
// is encountered, so this test doesn't apply.
359363
])("doesn't capture the same exception twice - %s", (_name: string, thrown: any) => {
364+
// Note: this is the same test as in `describe(captureException)`, except with the exception already wrapped in a
365+
// hint and accompanying an event. Duplicated here because some methods skip `captureException` and go straight to
366+
// `captureEvent`.
360367
const client = new TestClient({ dsn: PUBLIC_DSN });
361368
const event = { exception: { values: [{ type: 'Error', message: 'Will I get caught twice?' }] } };
362369
const hint = { originalException: thrown };

packages/utils/src/misc.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ export function stripUrlQueryAndFragment(urlPath: string): string {
252252
* normally would, which may or may not lead to them being caught again by something like the global error handler.)
253253
* This prevents us from actually recording it twice.
254254
*
255-
* Note: It will ignore primitives, as properties can't be set on them. {@link: Object.objectify} can be used on
256-
* exceptions to convert any that are primitives into their equivalent object wrapper forms so that this check will
257-
* always work. However, because we need to flag the exact object which will get rethrown, and because that rethrowing
258-
* happens outside of the event processing pipeline, the objectification must be done before the exception captured.
255+
* Note: It will ignore primitives (always return `false` and not mark them as seen), as properties can't be set on
256+
* them. {@link: Object.objectify} can be used on exceptions to convert any that are primitives into their equivalent
257+
* object wrapper forms so that this check will always work. However, because we need to flag the exact object which
258+
* will get rethrown, and because that rethrowing happens outside of the event processing pipeline, the objectification
259+
* must be done before the exception captured.
259260
*
260261
* @param A thrown exception to check or flag as having been seen
261262
* @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)

packages/utils/src/object.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export function dropUndefinedKeys<T>(val: T): T {
406406
* classes (String, Boolean, Number, etc.). Acts as the identity function on non-primitives.
407407
*
408408
* @param wat The subject of the objectification
409-
* @returns A version of "wat` which can safely be used with `Object` class methods
409+
* @returns A version of `wat` which can safely be used with `Object` class methods
410410
*/
411411
export function objectify(wat: unknown): typeof Object {
412412
let objectified;
@@ -428,6 +428,7 @@ export function objectify(wat: unknown): typeof Object {
428428
objectified = new (wat as any).constructor(wat);
429429
break;
430430

431+
// by process of elimination, at this point we know that `wat` must already be an object
431432
default:
432433
objectified = wat;
433434
break;

packages/utils/test/misc.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ describe('checkOrSetAlreadyCaught()', () => {
243243
});
244244

245245
it("recognizes exceptions it's seen before", () => {
246+
// `exception` can be any object - an `Error`, a class instance, or a plain object
246247
const exception = { message: 'Oh, no! Charlie ate the flip-flops! :-(', __sentry_captured__: true };
247248

248249
expect(checkOrSetAlreadyCaught(exception)).toBe(true);

0 commit comments

Comments
 (0)