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
Conversation
size-limit report 📦
|
b419764
to
c3043de
Compare
@@ -58,6 +58,10 @@ export function getReportDialogEndpoint( | |||
}, | |||
): string { | |||
const dsn = makeDsn(dsnLike); | |||
if (!dsn) { |
There was a problem hiding this comment.
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)
a991580
to
de3e675
Compare
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}`); |
There was a problem hiding this comment.
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
As discussed, we don't want to hard-throw if the SDK gets an invalid DSN. This PR fixes that by allowing
makeDsn
anddsnFromString
to returnundefined
, 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
tunnelRoute
optionmakeMultiplexedTransport
where I opted to resort to the fallback URL if an invalid URL is returned by the user matchercloses #8110