diff --git a/src/snapshots.js b/src/snapshots.js index c97d6d07..66ef6fc0 100644 --- a/src/snapshots.js +++ b/src/snapshots.js @@ -173,8 +173,8 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags // gather storybook data in parallel let [environmentInfo, stories] = yield* yieldAll([ - withPage(percy, aboutUrl, p => p.eval(evalStorybookEnvironmentInfo)), - withPage(percy, previewUrl, p => p.eval(evalStorybookStorySnapshots)) + withPage(percy, aboutUrl, p => p.eval(evalStorybookEnvironmentInfo), undefined, { from: 'about url', errorMessage: 'Unable to load about url' }), + withPage(percy, previewUrl, p => p.eval(evalStorybookStorySnapshots), undefined, { from: 'preview url', errorMessage: 'Unable to load preview url' }) ]); // map stories to snapshot options diff --git a/src/utils.js b/src/utils.js index 2f5b6eec..d99055dc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -145,9 +145,6 @@ export async function* withPage(percy, url, callback, retry, args) { let retries = 3; while (attempt < retries) { try { - if (attempt > 0) { - log.warn(`Retrying Story: ${args?.snapshotName}, attempt: ${attempt}`); - } // provide discovery options that may impact how the page loads let page = yield percy.browser.page({ networkIdleTimeout: percy.config.discovery.networkIdleTimeout, @@ -199,11 +196,25 @@ export async function* withPage(percy, url, callback, retry, args) { if (!(enableRetry === 'true') || attempt === retries) { // Add snapshotName to the error message const snapshotName = args?.snapshotName; + const errorMessage = args?.errorMessage; + if (errorMessage) { + error.message = `${errorMessage}: \n${error.message}`; + } if (snapshotName) { error.message = `Snapshot Name: ${snapshotName}: \n${error.message}`; } throw error; } + + // only throw warning message on snapshot + if (args?.snapshotName) { + log.warn(`Retrying Story: ${args.snapshotName}, attempt: ${attempt}`); + } + if (args?.from) { + log.warn( + `Retrying because error occurred in: ${args.from}, attempt: ${attempt}` + ); + } } } }