mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-10 22:54:45 +08:00
Sentry fix: Always gate reportError to avoid ResizeObserver errors
This commit is contained in:
parent
5b08d6f776
commit
9b91e09ff7
1 changed files with 30 additions and 2 deletions
|
@ -152,13 +152,26 @@ export default class AppEnvConstructor {
|
||||||
resourcePath: this.getLoadSettings().resourcePath,
|
resourcePath: this.getLoadSettings().resourcePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper function to check if an error should be ignored and not reported to Sentry
|
||||||
|
const shouldIgnoreError = (error: any): boolean => {
|
||||||
|
const errorMessage = `${error}`.toLowerCase();
|
||||||
|
|
||||||
|
// ResizeObserver errors happen infrequently but spam Sentry with thousands of reports
|
||||||
|
if (errorMessage.includes('resizeobserver')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add more ignored error patterns here as needed
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
|
// https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
|
||||||
window.onerror = (message, url, line, column, originalError) => {
|
window.onerror = (message, url, line, column, originalError) => {
|
||||||
if (!originalError && !message) return;
|
if (!originalError && !message) return;
|
||||||
if (!originalError) originalError = new Error(`${message}`);
|
if (!originalError) originalError = new Error(`${message}`);
|
||||||
|
|
||||||
if (`${originalError}`.toLowerCase().includes('resizeobserver')) {
|
if (shouldIgnoreError(originalError)) {
|
||||||
return; // happens infrequently, but errors a zillion times - too noisy for Sentry
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.inDevMode()) {
|
if (!this.inDevMode()) {
|
||||||
|
@ -169,10 +182,16 @@ export default class AppEnvConstructor {
|
||||||
};
|
};
|
||||||
|
|
||||||
process.on('uncaughtException', error => {
|
process.on('uncaughtException', error => {
|
||||||
|
if (shouldIgnoreError(error)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.reportError(error);
|
this.reportError(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('unhandledRejection', error => {
|
process.on('unhandledRejection', error => {
|
||||||
|
if (shouldIgnoreError(error)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.reportError(error);
|
this.reportError(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -181,14 +200,23 @@ export default class AppEnvConstructor {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
|
// https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
|
||||||
// In practice, it can have different shapes, so we make our best guess
|
// In practice, it can have different shapes, so we make our best guess
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
|
if (shouldIgnoreError(e)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.reportError(e);
|
this.reportError(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.reason) {
|
if (e.reason) {
|
||||||
|
if (shouldIgnoreError(e.reason)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.reportError(e.reason);
|
this.reportError(e.reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((e as any).detail && (e as any).detail.reason) {
|
if ((e as any).detail && (e as any).detail.reason) {
|
||||||
|
if (shouldIgnoreError((e as any).detail.reason)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.reportError((e as any).detail.reason);
|
this.reportError((e as any).detail.reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue