From 905d69a91cd5f78a25a32d27e67acf1dc63e5d12 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Fri, 25 Apr 2025 14:10:34 -0700 Subject: [PATCH 1/2] fix: Add polling error handling after begin migration --- lib/app/migrate.ts | 55 ++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/app/migrate.ts b/lib/app/migrate.ts index 41a3dce32..104f4d76b 100644 --- a/lib/app/migrate.ts +++ b/lib/app/migrate.ts @@ -30,6 +30,7 @@ import { isMigrationStatus, listAppsForMigration, MigrationApp, + MigrationFailed, MigrationStatus, } from '../../api/migrate'; import fs from 'fs'; @@ -92,6 +93,24 @@ function filterAppsByProjectName( }; } +function buildErrorMessageFromMigrationStatus(error: MigrationFailed): string { + const { componentErrors, projectErrorDetail } = error; + if (!componentErrors || !componentErrors.length) { + return projectErrorDetail; + } + return `${projectErrorDetail}: \n\t- ${componentErrors + .map(componentError => { + const { + componentType, + errorMessage, + developerSymbol: uid, + } = componentError; + + return `${componentType}${uid ? ` (${uid})` : ''}: ${errorMessage}`; + }) + .join('\n\t- ')}`; +} + async function fetchMigrationApps( appId: MigrateAppArgs['appId'], derivedAccountId: number, @@ -359,11 +378,20 @@ async function beginMigration( ); const { migrationId } = data; - const pollResponse = await pollMigrationStatus( - derivedAccountId, - migrationId, - [MIGRATION_STATUS.INPUT_REQUIRED] - ); + let pollResponse: MigrationStatus; + try { + pollResponse = await pollMigrationStatus(derivedAccountId, migrationId, [ + MIGRATION_STATUS.INPUT_REQUIRED, + ]); + } catch (error) { + SpinniesManager.fail('beginningMigration', { + text: lib.migrate.spinners.unableToStartMigration, + }); + if (isMigrationStatus(error) && error.status === MIGRATION_STATUS.FAILURE) { + throw new Error(buildErrorMessageFromMigrationStatus(error)); + } + throw error; + } if (pollResponse.status !== MIGRATION_STATUS.INPUT_REQUIRED) { SpinniesManager.fail('beginningMigration', { @@ -436,22 +464,7 @@ async function finalizeMigration( }); if (isMigrationStatus(error) && error.status === MIGRATION_STATUS.FAILURE) { - const { componentErrors, projectErrorDetail } = error; - if (!componentErrors || !componentErrors.length) { - throw new Error(projectErrorDetail); - } - const errorMessage = `${projectErrorDetail}: \n\t- ${componentErrors - .map(componentError => { - const { - componentType, - errorMessage, - developerSymbol: uid, - } = componentError; - - return `${componentType}${uid ? ` (${uid})` : ''}: ${errorMessage}`; - }) - .join('\n\t- ')}`; - throw new Error(errorMessage); + throw new Error(buildErrorMessageFromMigrationStatus(error)); } throw new Error(lib.migrate.errors.migrationFailed, { From 8d577f7090f0e554df63dcf1c9d5582a0fd84f16 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Fri, 25 Apr 2025 14:54:17 -0700 Subject: [PATCH 2/2] improve error --- lib/app/migrate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/app/migrate.ts b/lib/app/migrate.ts index 104f4d76b..8896308c6 100644 --- a/lib/app/migrate.ts +++ b/lib/app/migrate.ts @@ -390,7 +390,9 @@ async function beginMigration( if (isMigrationStatus(error) && error.status === MIGRATION_STATUS.FAILURE) { throw new Error(buildErrorMessageFromMigrationStatus(error)); } - throw error; + throw new Error(lib.migrate.errors.migrationFailed, { + cause: error, + }); } if (pollResponse.status !== MIGRATION_STATUS.INPUT_REQUIRED) {