From 530f98694e79e9b7c1b6df71acff829fc17c4dea Mon Sep 17 00:00:00 2001 From: Daniel Rozenberg Date: Mon, 20 May 2024 13:22:56 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=F0=9F=90=9B=20Fix=20incorrect=20th?= =?UTF-8?q?rottle=20function=20for=20error=20reporting=20(#40015)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error-reporting.js | 4 ++-- test/unit/test-error-reporting.js | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/error-reporting.js b/src/error-reporting.js index 268c29dbe4e4..20f747708e30 100644 --- a/src/error-reporting.js +++ b/src/error-reporting.js @@ -526,7 +526,7 @@ export function getErrorReportData( ) { expected = true; - if (throttleBase > NON_ACTIONABLE_ERROR_THROTTLE_THRESHOLD) { + if (throttleBase < NON_ACTIONABLE_ERROR_THROTTLE_THRESHOLD) { return; } } @@ -534,7 +534,7 @@ export function getErrorReportData( const isUserError = isUserErrorMessage(message); // Only report a subset of user errors. - if (isUserError && throttleBase > USER_ERROR_THROTTLE_THRESHOLD) { + if (isUserError && throttleBase < USER_ERROR_THROTTLE_THRESHOLD) { return; } diff --git a/test/unit/test-error-reporting.js b/test/unit/test-error-reporting.js index edfdde9f0e89..6325f4213fc4 100644 --- a/test/unit/test-error-reporting.js +++ b/test/unit/test-error-reporting.js @@ -189,7 +189,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { beforeEach(() => { onError = window.onerror; - nextRandomNumber = 0; + nextRandomNumber = 1; env.sandbox.stub(Math, 'random').callsFake(() => nextRandomNumber); self.__AMP_MODE = undefined; }); @@ -500,7 +500,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { }); it('should throttle user errors', () => { - nextRandomNumber = 0.2; + nextRandomNumber = 0.0099999; let e = ''; allowConsoleError(() => { try { @@ -520,7 +520,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { }); it('should not report load errors', () => { - nextRandomNumber = 1e-3 + 1e-4; + nextRandomNumber = 0.000099999; const e = new Error('Failed to load:'); const data = getErrorReportData( undefined, @@ -533,7 +533,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { }); it('should report throttled load errors at threshold', () => { - nextRandomNumber = 1e-4; + nextRandomNumber = 0.0001; const e = new Error('Failed to load:'); const data = getErrorReportData( undefined, @@ -547,7 +547,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { }); it('should not report Script errors', () => { - nextRandomNumber = 1e-3 + 1e-4; + nextRandomNumber = 0.000099999; const e = new Error('Script error.'); const data = getErrorReportData( undefined, @@ -560,7 +560,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { }); it('should report throttled Script errors at threshold', () => { - nextRandomNumber = 1e-4; + nextRandomNumber = 0.0001; const e = new Error('Script error.'); const data = getErrorReportData( undefined, @@ -574,7 +574,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => { }); it('should report throttled load errors under threshold', () => { - nextRandomNumber = 1e-4 - 1e-5; + nextRandomNumber = 0.0001; const e = new Error('Failed to load:'); const data = getErrorReportData( undefined,