Skip to content

Improve EventHint typing to account for error-like objects #7344

Description

@pfdzm

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g. bundle.tracing.min.js) in your SDK setup.

@sentry/vue

SDK Version

7.35.0

Framework Version

No response

Link to Sentry event

https://afilio.sentry.io/issues/3897188605/events/30d6c162b1844dbd912886cab3b414e0/

SDK Setup

{enabled: environment!=="development"&&!browserCheckFailed,dsn: [redacted],tunnel: "/track-error",integrations: [newBrowserTracing(),newSentry.Replay({maskAllText: false,}),],tracesSampleRate: 0.01,release: process.env.CODE_VERSION,
environment,ignoreErrors: [/Non-Errorpromiserejectioncapturedwithvalue:ObjectNotFoundMatchingId:\d+/,],beforeSend: (event,hint)=>{constcap=levelCap(hint);constlevels: Sentry.SeverityLevel[]=["debug","info","warning","error","fatal",];if(levels.indexOf(cap)<levels.indexOf(event.level??"fatal")){event.level=cap;}returndiscardChromeExtensionErrors(enrichWithAdditionalData(event,hint));},beforeBreadcrumb: (breadcrumb)=>{if(breadcrumb.category==="fetch"||breadcrumb.category==="xhr"){constignoredHosts=["redacted","redacted"];consturl=newURL(expectString(breadcrumb.data?.url));if(ignoredHosts.includes(url.hostname)){returnnull;}}returnbreadcrumb;},replaysSessionSampleRate: 0.1,replaysOnErrorSampleRate: 1.0,}

Steps to Reproduce

The type definitions provided for beforeSend or more specifically the EventHint's originalException say it will be string | Error | undefined | null. However, we have errors from our beforeSend hook where we apply a "level cap" (i.e. downgrade some error levels) based on the error name (please see the linked event).

Expected Result

I would expect the name property of an Error to always exist (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) - otherwise the types should be updated to reflect what can actually happen.

Actual Result

name of an Error is undefined, causing an uncaught exception to happen in our beforeSend hook.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions