Skip to content

Commit 98394f1

Browse files
authored
fix: Capture unexpected TypeError when capturing RouteError (#16327)
fix: Capture unexpected Type Error in capturing RouteError Wraps unreproducible TypeError (missing setter) in Error.message property in a try-catch. When the TypeError is thrown it causes the initial RouteError to be ignored and the newer and less informative TypeError to be captured by Sentry instead. Currently, a minority of users are affected and certain browser and/or browser extension incompatibility is suspected. By capturing the new TypeError, and returning to the RouteError context, we are then able to capture the emitted RouteError. This should help in the discovery of the actual errors causing the RouteError and perhaps uncover the root cause of the TypeError. Fixes GH-16314 Fixes Sentry-JAVASCRIPT-129Q
1 parent 599933c commit 98394f1

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/sentry/static/sentry/app/views/routeError.jsx

+23-5
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,35 @@ class RouteError extends React.Component {
3535
}
3636

3737
const route = getRouteStringFromRoutes(routes);
38+
const enrichScopeContext = scope => {
39+
scope.setExtra('route', route);
40+
scope.setExtra('orgFeatures', (organization && organization.features) || []);
41+
scope.setExtra('orgAccess', (organization && organization.access) || []);
42+
scope.setExtra('projectFeatures', (project && project.features) || []);
43+
return scope;
44+
};
45+
3846
if (route) {
39-
error.message = `${error.message}: ${route}`;
47+
/**
48+
* Unexpectedly, error.message would sometimes not have a setter property, causing another exception to be thrown,
49+
* and losing the original error in the process. Wrapping the mutation in a try-catch in an attempt to preserve
50+
* the original error for logging.
51+
* See https://github.com/getsentry/sentry/issues/16314 for more details.
52+
*/
53+
try {
54+
error.message = `${error.message}: ${route}`;
55+
} catch (e) {
56+
Sentry.withScope(scope => {
57+
enrichScopeContext(scope);
58+
Sentry.captureException(e);
59+
});
60+
}
4061
}
4162
// TODO(dcramer): show something in addition to embed (that contains it?)
4263
// throw this in a timeout so if it errors we dont fall over
4364
this._timeout = window.setTimeout(() => {
4465
Sentry.withScope(scope => {
45-
scope.setExtra('route', route);
46-
scope.setExtra('orgFeatures', (organization && organization.features) || []);
47-
scope.setExtra('orgAccess', (organization && organization.access) || []);
48-
scope.setExtra('projectFeatures', (project && project.features) || []);
66+
enrichScopeContext(scope);
4967
Sentry.captureException(error);
5068
});
5169

0 commit comments

Comments
 (0)