From 68419be04b43ebdc756d2aa56fcda61c591d4793 Mon Sep 17 00:00:00 2001 From: Alexander Moses Date: Fri, 15 May 2026 13:16:06 +0000 Subject: [PATCH 1/2] Bug-2003889: Return an appropriate message when lando is still loading - Updated the response message in src/logic/treeherder.ts to convey to the user that lando has still not completed the try pushes. - Added the required unit tests --- src/__tests__/App.test.tsx | 29 +++ src/__tests__/__snapshots__/App.test.tsx.snap | 201 ++++++++++++++++++ src/logic/treeherder.ts | 29 ++- 3 files changed, 252 insertions(+), 7 deletions(-) diff --git a/src/__tests__/App.test.tsx b/src/__tests__/App.test.tsx index a418178d9..e0e464156 100644 --- a/src/__tests__/App.test.tsx +++ b/src/__tests__/App.test.tsx @@ -148,6 +148,35 @@ describe('App', () => { expect(document.body).toMatchSnapshot(); }); + it('Should render the correct error message to the console when new_revision is required but missing', async () => { + // Silence console.error for a better console output. + jest.spyOn(console, 'error').mockImplementation(() => {}); + fetchMock.get( + 'begin:https://treeherder.mozilla.org/api/perfcompare/results/', + { + status: 400, + body: JSON.stringify({ + new_revision: ['This field may not be blank.'], + }), + }, + ); + + await router.navigate( + '/compare-results/?baseRev=spam&baseRepo=mozilla-central&framework=2', + ); + render(); + + await screen.findByText(/Error/); + expect(console.error).toHaveBeenCalledWith( + new Error( + 'The comparison cannot be performed because the `new_revision` field is missing. ' + + 'This typically happens when the `mach try perf` push is still being processed by Lando. ' + + 'Please wait a few moments for the push to complete and then refresh the page.', + ), + ); + expect(document.body).toMatchSnapshot(); + }); + it('Should render an error page for compare over time when the treeherder request fails with an error 400', async () => { // Silence console.error for a better console output. We'll check its result later. jest.spyOn(console, 'error').mockImplementation(() => {}); diff --git a/src/__tests__/__snapshots__/App.test.tsx.snap b/src/__tests__/__snapshots__/App.test.tsx.snap index af36bb4d7..a28fd4f68 100644 --- a/src/__tests__/__snapshots__/App.test.tsx.snap +++ b/src/__tests__/__snapshots__/App.test.tsx.snap @@ -695,3 +695,204 @@ exports[`App CompareResults or CompareOverTime loader Should render an error pag `; + +exports[`App CompareResults or CompareOverTime loader Should render the correct error message to the console when new_revision is required but missing 1`] = ` + +
+ + +`; diff --git a/src/logic/treeherder.ts b/src/logic/treeherder.ts index 45fb9bf45..4bc46bfec 100644 --- a/src/logic/treeherder.ts +++ b/src/logic/treeherder.ts @@ -85,15 +85,30 @@ export async function fetchRevisionFromHash( async function fetchFromTreeherder(url: string) { const response = await fetch(url); if (!response.ok) { + const errorText = await response.text(); if (response.status === 400) { - throw new Error( - `Error when requesting treeherder: ${await response.text()}`, - ); - } else { - throw new Error( - `Error when requesting treeherder: (${response.status}) ${response.statusText}`, - ); + let errorJson: Record | null = null; + try { + errorJson = JSON.parse(errorText) as Record; + } catch { + // Fall through to the generic error below if parsing fails + } + + if ( + errorJson?.new_revision?.[0]?.trim() === 'This field may not be blank.' + ) { + throw new Error( + 'The comparison cannot be performed because the `new_revision` field is missing. ' + + 'This typically happens when the `mach try perf` push is still being processed by Lando. ' + + 'Please wait a few moments for the push to complete and then refresh the page.', + ); + } + + throw new Error(`Error when requesting treeherder: ${errorText}`); } + throw new Error( + `Error when requesting treeherder: (${response.status}) ${response.statusText}`, + ); } return response; } From fa20599aaefae7e4b92416b7cb449755a613e2b6 Mon Sep 17 00:00:00 2001 From: Alexander Moses Date: Wed, 20 May 2026 19:07:56 +0000 Subject: [PATCH 2/2] Bug-2003889: Fixing snapshots Fixing snapshots after running `npm ci && npm run fix-all`. --- src/__tests__/__snapshots__/App.test.tsx.snap | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/__tests__/__snapshots__/App.test.tsx.snap b/src/__tests__/__snapshots__/App.test.tsx.snap index a28fd4f68..59d67bcc0 100644 --- a/src/__tests__/__snapshots__/App.test.tsx.snap +++ b/src/__tests__/__snapshots__/App.test.tsx.snap @@ -708,7 +708,7 @@ exports[`App CompareResults or CompareOverTime loader Should render the correct class="fcndgf6" >
Dark mode
+

+ PerfCompare +

-
-

- PerfCompare -

-