Skip to content

Commit 7e4f25e

Browse files
Turbo87kamilogorek
authored andcommitted
fix: [browser/LinkedErrors] Fix limit to include the original exception (#1699)
Up until now the `limit` option only counted the linked errors, but not the original exception. After this commit the `limit` will correspond to the number of exceptions that are actually being displayed by Sentry in the end.
1 parent ddc74b7 commit 7e4f25e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/browser/src/integrations/linkederrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class LinkedErrors implements Integration {
7272
* @inheritDoc
7373
*/
7474
public walkErrorTree(error: ExtendedError, key: string, stack: SentryException[] = []): SentryException[] {
75-
if (!(error[key] instanceof Error) || stack.length >= this.limit) {
75+
if (!(error[key] instanceof Error) || stack.length + 1 >= this.limit) {
7676
return stack;
7777
}
7878
const stacktrace = computeStackTrace(error[key]);

packages/browser/test/integrations/linkederrors.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,35 @@ describe('LinkedErrors', () => {
114114
expect(result!.exception!.values![2].value).equal('three');
115115
expect(result!.exception!.values![2].stacktrace).to.have.property('frames');
116116
});
117+
118+
it('should allow to change stack size limit', async () => {
119+
linkedErrors = new LinkedErrors({
120+
limit: 2,
121+
});
122+
123+
const three: ExtendedError = new SyntaxError('three');
124+
125+
const two: ExtendedError = new TypeError('two');
126+
two.cause = three;
127+
128+
const one: ExtendedError = new Error('one');
129+
one.cause = two;
130+
131+
const originalException = one;
132+
const backend = new BrowserBackend({});
133+
const event = await backend.eventFromException(originalException);
134+
const result = linkedErrors.handler(event, {
135+
originalException,
136+
});
137+
138+
// It shouldn't include root exception, as it's already processed in the event by the main error handler
139+
expect(result!.exception!.values!.length).equal(2);
140+
expect(result!.exception!.values![0].type).equal('Error');
141+
expect(result!.exception!.values![0].value).equal('one');
142+
expect(result!.exception!.values![0].stacktrace).to.have.property('frames');
143+
expect(result!.exception!.values![1].type).equal('TypeError');
144+
expect(result!.exception!.values![1].value).equal('two');
145+
expect(result!.exception!.values![1].stacktrace).to.have.property('frames');
146+
});
117147
});
118148
});

0 commit comments

Comments
 (0)