Skip to content
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

fix(utils): Fail silently if the provided Dsn is invalid #8121

Merged
merged 5 commits into from May 17, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented May 15, 2023

As discussed, we don't want to hard-throw if the SDK gets an invalid DSN. This PR fixes that by allowing makeDsn and dsnFromString to return undefined, which we do if the Dsn is invalid. This is a breaking change for the utils package but since it's utils we're fine with that.

(The alternative, try-catching the respective function calls didn't seem much nicer to me, especially considering that we rarely use throwing and try/catching for control flow in the SDK).

This required changes in more places, since we don't only work with raw DSNs in the BaseClient but also in

  • NextJS for the tunnelRoute option
  • makeMultiplexedTransport where I opted to resort to the fallback URL if an invalid URL is returned by the user matcher

closes #8110

@Lms24 Lms24 requested review from lforst and AbhiPrasad May 15, 2023 15:59
@github-actions
Copy link
Contributor

github-actions bot commented May 15, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.03 KB (+0.06% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 65.68 KB (+0.09% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.59 KB (+0.11% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 58.15 KB (+0.12% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.2 KB (+0.16% 🔺)
@sentry/browser - Webpack (minified) 69.07 KB (+0.05% 🔺)
@sentry/react - Webpack (gzipped + minified) 21.22 KB (+0.16% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.16 KB (+0.09% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.65 KB (+0.03% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.9 KB (+0.08% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 48.13 KB (+1.1% 🔺)
@sentry/replay - Webpack (gzipped + minified) 42.02 KB (+1.35% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 67.1 KB (+0.9% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 60 KB (+1.05% 🔺)

@Lms24 Lms24 force-pushed the lms/dont-throw-invalid-dsn-error branch from b419764 to c3043de Compare May 16, 2023 13:20
@@ -58,6 +58,10 @@ export function getReportDialogEndpoint(
},
): string {
const dsn = makeDsn(dsnLike);
if (!dsn) {
Copy link
Member Author

@Lms24 Lms24 May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just return an empty script tag instead of throwing, causing the dialog not to be fetched (which is fine IMO)

@Lms24 Lms24 force-pushed the lms/dont-throw-invalid-dsn-error branch from a991580 to de3e675 Compare May 16, 2023 14:18
throw new SentryError(`Invalid Sentry Dsn: ${str}`);
// This should be logged to the console
// eslint-disable-next-line no-console
console.error(`Invalid Sentry Dsn: ${str}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to log this as a console error so that this error is easier to spot. More fine-grained validation is still only logged if debug is set

@Lms24 Lms24 merged commit 6bf5d3a into develop May 17, 2023
62 checks passed
@Lms24 Lms24 deleted the lms/dont-throw-invalid-dsn-error branch May 17, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDK crashes if malformed DSN is provided
2 participants