Use of `any` in captureException Typing Leads to Errors Throughout the SDK
See original GitHub issueIs there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
SDK Version
7.13.0
Framework Version
No response
Link to Sentry event
Steps to Reproduce
this.hub = getCurrentHub();
this.hub?.captureException(void 0);
Expected Result
Well, this shouldn’t be possible.
I would expect that @sentry/hub would be catching the fact that the value is invalid.
Actual Result
An error is thrown, as described here: https://github.com/getsentry/sentry-javascript/issues/5622#issuecomment-1250343554
I would really expect the sentry packages to have better error handling, especially considered how they’ve been made interdependent. Instead, we get vague error messages that we have to debug ourselves, rather than package-level error handling, custom errors thrown with proper codes.
This also bleeds into this change: https://github.com/getsentry/sentry-javascript/pull/5497/files#r973748050, where _handler
was checked but the value of the event
was never verified. A curious oversight if there were concerns about version conflicts and unknown sources of error.
This line: https://github.com/getsentry/sentry-javascript/blob/9862a32899a41a3af9a5cd87c0d4a09a1d689e25/packages/types/src/hub.ts#L80 is the source of the troubles for both concerns. I’m not sure how this passed review given the number of things that hub interacts with. The use of any
here is wholly incorrect and should at least filter to defined
and not null
. The problem is also pervasive for every definition of captureException
including https://github.com/getsentry/sentry-javascript/blob/9862a32899a41a3af9a5cd87c0d4a09a1d689e25/packages/types/src/client.ts#L30
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Your own test, as linked above, is the reproduction. Choosing to do nothing is simply lazy.
That is totally fine. If anybody else encounters this issue and can provide a reproduction example, ping us here and we will reopen! 👍