Our suite runs with retries on: every failing test gets one more attempt in CI (retries: { runMode: 1 }). And for months, our failure report showed us the wrong error every single time a test failed twice.
Now, here is where the plot thickens. Attempt 2 rarely starts on a clean slate:
Attempt 1 → fails on the real bug, leaving behind a used coupon, a saved cart or a deleted download
Attempt 2 → crashes on that leftover state with a completely unrelated error
Report → Cypress hands you Attempt 2's error, so you spend half an hour chasing a phantom
Here's the kind of pair I mean:

Attempt 1 had the real bug: the coupon didn't change the total. Attempt 2 complained that the coupon was already used, because attempt 1 had used it. Guess which one we spent time investigating? Attempt 2 (of course).
Why your reporter never sees attempt 1
In the Cypress run results, displayError holds the last attempt's error, and attempts[] only records whether each attempt passed or failed, with no error text. By the time after:run fires, attempt 1's error is gone. You have to grab it in the browser while that attempt is still alive.
Catch it in afterEach
afterEach runs after failed attempts too, and this.currentTest.err holds that attempt's error. Send it to Node:
// cypress/support/e2e.ts
afterEach(function () {
const test = this.currentTest;
if (test?.state !== 'failed' || !test.err) return;
cy.task(
'rememberFailure',
{
title: test.titlePath().join(' › '),
attempt: Cypress.currentRetry + 1,
error: test.err.stack ?? `${test.err.name}: ${test.err.message}`,
},
{ log: false }
);
});
Then in setupNodeEvents, keep the first error and refuse to overwrite it:
// cypress.config.ts
const firstFailure: Record<string, string> = {};
on('task', {
rememberFailure({ title, attempt, error }) {
firstFailure[title] ??= `attempt ${attempt}: ${error}`;
return null;
},
});
Wherever you build your report, prefer firstFailure[title] over displayError. That ??= is the entire fix. A plain = lets every retry overwrite the entry, and the report keeps showing attempt 2 anyway (yes, that was my first draft).
How I verify it's capturing attempt 1
Drop in a throwaway test that fails differently on each retry:
it('fails twice, differently', () => {
expect(Cypress.currentRetry, 'first attempt').to.equal(99);
});
Attempt 1 fails with expected 0 to equal 99; attempt 2 fails with expected 1 to equal 99. Your report must show 0. If it shows 1, you're still reading the tail end.
Run the same check on a test that passes on its retry. It's flaky, not green, and its attempt-1 error is the most valuable signal in the whole run.
One retry gotcha to keep in mind
Tests that depend on an earlier test break in their own creative ways once retries kick in. Picture a spec that exports orders to CSV in test 1 and imports that file in test 2. When test 2 retries, the cleanup from its first attempt has already deleted the file. Clean up once in after(), and empty the downloads folder before you trigger a new export, not right after reading it.
Full spec to verify attempt-1 error capture
Drop this spec into your suite to check that the afterEach and ??= wiring handles permanent failures, flaky retries and a retry-safe download:
// cypress/e2e/retry-errors.cy.ts
describe('Retry error capture', { retries: { runMode: 1, openMode: 1 } }, () => {
beforeEach(() => {
cy.task('emptyDownloads');
});
after(() => {
cy.task('emptyDownloads');
});
it('keeps attempt 1 when attempt 2 fails differently', () => {
expect(Cypress.currentRetry, 'attempt index').to.equal(99);
});
it('keeps attempt 1 when attempt 2 passes', () => {
expect(Cypress.currentRetry, 'passes on retry').to.equal(1);
});
it('exports orders on every attempt', () => {
cy.visit('/orders');
cy.get('[data-cy="export-csv"]').click();
cy.readFile('cypress/downloads/orders.csv').should('contain', 'Order ID');
});
});
emptyDownloads is a two-line task: fs.rmSync(config.downloadsFolder, { recursive: true, force: true }) and return null. Run the spec headless once and open your report: test 1 shows expected 0 to equal 99, test 2 shows up as flaky with attempt 1's error attached, and test 3 survives a retry because the folder is emptied before the export.

Recap: what you need to do
- Add an
afterEachincypress/support/e2e.tsthat checksthis.currentTest?.state === 'failed'and sends{ title, attempt, error }to Node withcy.task(..., { log: false }). - Store it in
setupNodeEventswith??=(never a plain=), so attempt 2 can't overwrite attempt 1. - Read that first error before Cypress's
displayErrorin your report, including for tests that pass on retry. - Empty the downloads folder before an export and once in
after(), so a retry never loses a file it still needs.
If you only have time to read one error from a retried test, make sure it's the first one. Happy testing!
