Skip to content
Merged
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
57 changes: 36 additions & 21 deletions lib/app/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isMigrationStatus,
listAppsForMigration,
MigrationApp,
MigrationFailed,
MigrationStatus,
} from '../../api/migrate';
import fs from 'fs';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -359,11 +378,22 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but we do have isSpecifiedError in LDL that you could use here (doesn't buy you a ton tbh, outside of maybe consistency in util usage)

Copy link
Contributor Author

@joe-yeager joe-yeager Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. These aren't actually Error objects, our polling util rejects with plain objects that look like:

{
   status: "FAILURE" | "SOME_OTHER_STATUS"
   ... other fields
}

Wheres isSpecifiedError only operates on HubSpotHttpErrors

throw new Error(buildErrorMessageFromMigrationStatus(error));
}
throw new Error(lib.migrate.errors.migrationFailed, {
cause: error,
});
}

if (pollResponse.status !== MIGRATION_STATUS.INPUT_REQUIRED) {
SpinniesManager.fail('beginningMigration', {
Expand Down Expand Up @@ -436,22 +466,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, {
Expand Down