-
-
Notifications
You must be signed in to change notification settings - Fork 343
fix(promise-tracking): Remove Sentry frames from synthetic errors #3423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8f58e1d
update changelog
krystofwoldrich 0b4490d
fix lint
krystofwoldrich 8079b13
fix(promise-tracking): Remove Sentry frames from synthetic errors
krystofwoldrich 9d7c3ba
More refactor and add tests
krystofwoldrich b91705e
Merge branch 'kw-fix-local-synthetic-symbolication' into kw-fix-onunh…
krystofwoldrich e2a4735
Add skip frames tests
krystofwoldrich c33bd32
Add test
krystofwoldrich 66aeba6
add isErrorLike and only create synthetic error when needed
krystofwoldrich da6cb09
Update src/js/utils/error.ts
krystofwoldrich f733433
fix gh suggestion
krystofwoldrich b090287
fix prettier
krystofwoldrich 7ba69b6
Merge remote-tracking branch 'origin/main' into kw-fix-local-syntheti…
krystofwoldrich daa76e2
Merge branch 'kw-fix-local-synthetic-symbolication' into kw-fix-onunh…
krystofwoldrich 717324a
Merge branch 'main' into kw-fix-onunhandled-synthetic-stack
krystofwoldrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export interface ExtendedError extends Error { | ||
framesToPop?: number | undefined; | ||
} | ||
|
||
// Sentry Stack Parser is skipping lines not frames | ||
// https://github.com/getsentry/sentry-javascript/blob/739d904342aaf9327312f409952f14ceff4ae1ab/packages/utils/src/stacktrace.ts#L23 | ||
// 1 for first line with the Error message | ||
const SENTRY_STACK_PARSER_OFFSET = 1; | ||
const REMOVE_ERROR_CREATION_FRAMES = 2 + SENTRY_STACK_PARSER_OFFSET; | ||
|
||
/** | ||
* Creates synthetic trace. By default pops 2 frames - `createSyntheticError` and the caller | ||
*/ | ||
export function createSyntheticError(framesToPop: number = 0): ExtendedError { | ||
const error: ExtendedError = new Error(); | ||
error.framesToPop = framesToPop + REMOVE_ERROR_CREATION_FRAMES; // Skip createSyntheticError's own stack frame. | ||
return error; | ||
} | ||
|
||
/** | ||
* Returns the number of frames to pop from the stack trace. | ||
* @param error ExtendedError | ||
*/ | ||
export function getFramesToPop(error: ExtendedError): number { | ||
return error.framesToPop !== undefined ? error.framesToPop : 0; | ||
} | ||
|
||
/** | ||
* Check if `potentialError` is an object with string stack property. | ||
*/ | ||
export function isErrorLike(potentialError: unknown): potentialError is { stack: string } { | ||
return ( | ||
potentialError !== null && | ||
typeof potentialError === 'object' && | ||
'stack' in potentialError && | ||
typeof potentialError.stack === 'string' | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { isErrorLike } from '../src/js/utils/error'; | ||
|
||
describe('error', () => { | ||
describe('isErrorLike', () => { | ||
test('returns true for Error object', () => { | ||
expect(isErrorLike(new Error('test'))).toBe(true); | ||
}); | ||
|
||
test('returns true for ErrorLike object', () => { | ||
expect(isErrorLike({ stack: 'test' })).toBe(true); | ||
}); | ||
|
||
test('returns false for non object', () => { | ||
expect(isErrorLike('test')).toBe(false); | ||
}); | ||
|
||
test('returns false for object without stack', () => { | ||
expect(isErrorLike({})).toBe(false); | ||
}); | ||
|
||
test('returns false for object with non string stack', () => { | ||
expect(isErrorLike({ stack: 1 })).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.