Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<App />);

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(() => {});
Expand Down
197 changes: 197 additions & 0 deletions src/__tests__/__snapshots__/App.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,200 @@ exports[`App CompareResults or CompareOverTime loader Should render an error pag
</div>
</body>
`;

exports[`App CompareResults or CompareOverTime loader Should render the correct error message to the console when new_revision is required but missing 1`] = `
<body>
<div>
<div
aria-live="assertive"
class="alert-container"
role="alert"
/>
<div
class="fcndgf6"
>
<div
class="MuiGrid-root MuiGrid-direction-xs-row header-container container_f16a4r9k css-k4qgqg-MuiGrid-root"
>
<div
class="MuiBox-root css-1e39pab"
>
<div
class="toggle-dark-mode f1y1dem6 MuiBox-root css-0"
>
<div
class="MuiFormGroup-root css-1mac7pt-MuiFormGroup-root"
>
<label
class="MuiFormControlLabel-root MuiFormControlLabel-labelPlacementStart toggle-text css-1lhdpr4-MuiFormControlLabel-root"
>
<span
class="MuiSwitch-root MuiSwitch-sizeMedium toggle-switch toggle-dark-mode css-rehya9-MuiSwitch-root"
>
<span
class="MuiButtonBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary PrivateSwitchBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary css-1jkkk7l-MuiButtonBase-root-MuiSwitchBase-root-MuiSwitch-switchBase"
>
<input
aria-label="Dark mode switch"
class="PrivateSwitchBase-input MuiSwitch-input css-12xagqm-MuiSwitchBase-root"
id="Dark mode"
name="toggle-dark-mode"
role="switch"
type="checkbox"
/>
<span
class="MuiSwitch-thumb css-1mw77bv-MuiSwitch-thumb"
/>
</span>
<span
class="MuiSwitch-track css-1kf3qur-MuiSwitch-track"
/>
</span>
<span
class="MuiTypography-root MuiTypography-body1 MuiFormControlLabel-label css-n290n7-MuiTypography-root"
>
Dark mode
</span>
</label>
</div>
</div>
<h2
class="MuiTypography-root MuiTypography-h2 perfcompare-header css-1lhc7rx-MuiTypography-root"
>
PerfCompare
</h2>
<div
class="MuiBox-root css-u7c4o"
>
<div
class="MuiBox-root css-0"
>
<a
aria-label="Docs"
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-husciy-MuiTypography-root-MuiLink-root"
href="https://firefox-source-docs.mozilla.org/testing/perfdocs/perfcompare.html"
target="_blank"
title="View the documentation"
>
<div
class="MuiStack-root css-ljomt-MuiStack-root"
>
<span
class="MuiBox-root css-0"
>
Docs
</span>
</div>
</a>
</div>
<div
class="MuiBox-root css-0"
>
<a
aria-label="Source"
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-husciy-MuiTypography-root-MuiLink-root"
href="https://github.com/mozilla/perfcompare"
target="_blank"
title="View the source code on GitHub"
>
<div
class="MuiStack-root css-ljomt-MuiStack-root"
>
<span
class="MuiBox-root css-0"
>
Source
</span>
</div>
</a>
</div>
<div
class="MuiBox-root css-0"
>
<a
aria-label="Matrix"
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-husciy-MuiTypography-root-MuiLink-root"
href="https://matrix.to/#/#perfcompare:mozilla.org"
target="_blank"
title="Chat with us on Matrix"
>
<div
class="MuiStack-root css-ljomt-MuiStack-root"
>
<span
class="MuiBox-root css-0"
>
Matrix
</span>
</div>
</a>
</div>
<div
class="MuiBox-root css-0"
>
<a
aria-label="Bugzilla"
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-husciy-MuiTypography-root-MuiLink-root"
href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=PerfCompare&status_whiteboard=[pcf]"
target="_blank"
title="Report an issue on Bugzilla"
>
<div
class="MuiStack-root css-ljomt-MuiStack-root"
>
<span
class="MuiBox-root css-0"
>
Bugzilla
</span>
</div>
</a>
</div>
</div>
</div>
</div>
<section
class="container_f13838vn"
>
<div
class="MuiBox-root css-i3pbo"
>
<a
aria-label="link to home"
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-725yfl-MuiTypography-root-MuiLink-root"
href="/"
>
<div
class="MuiStack-root css-ljomt-MuiStack-root"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall css-54rgmy-MuiSvgIcon-root"
data-testid="ChevronLeftIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z"
/>
</svg>
<span
class="MuiBox-root css-0"
>
Home
</span>
</div>
</a>
</div>
<p>
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.
</p>
<p>
More information about this error has been written to the Web Console.
</p>
</section>
</div>
</div>
</body>
`;
29 changes: 22 additions & 7 deletions src/logic/treeherder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]> | null = null;
try {
errorJson = JSON.parse(errorText) as Record<string, string[]>;
} 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;
}
Expand Down