Skip to content

Commit

Permalink
πŸ—πŸ› Fix incorrect throttle function for error reporting (#40015)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrozenberg authored May 20, 2024
1 parent d15fbae commit 530f986
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/error-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,15 @@ export function getErrorReportData(
) {
expected = true;

if (throttleBase > NON_ACTIONABLE_ERROR_THROTTLE_THRESHOLD) {
if (throttleBase < NON_ACTIONABLE_ERROR_THROTTLE_THRESHOLD) {
return;
}
}

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;
}

Expand Down
14 changes: 7 additions & 7 deletions test/unit/test-error-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -500,7 +500,7 @@ describes.sandboxed('getErrorReportData', {}, (env) => {
});

it('should throttle user errors', () => {
nextRandomNumber = 0.2;
nextRandomNumber = 0.0099999;
let e = '';
allowConsoleError(() => {
try {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 530f986

Please sign in to comment.