Improve add field to view script to handle errors (#6232)

Adding logs and catching errors to continue not to block the script
execution if the command fails for one workspace
This commit is contained in:
Marie
2024-07-12 10:22:51 +02:00
committed by GitHub
parent 4350279c64
commit ad5d0905cc

View File

@ -80,6 +80,8 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
} }
for (const workspaceId of workspaceIds) { for (const workspaceId of workspaceIds) {
this.logger.log(`Running command for workspace ${workspaceId}`);
try {
const viewFieldRepository = const viewFieldRepository =
await this.twentyORMManager.getRepositoryForWorkspace( await this.twentyORMManager.getRepositoryForWorkspace(
workspaceId, workspaceId,
@ -96,7 +98,6 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
await this.typeORMService.connectToDataSource(dataSourceMetadata); await this.typeORMService.connectToDataSource(dataSourceMetadata);
if (workspaceDataSource) { if (workspaceDataSource) {
try {
const newAddressField = await this.fieldMetadataRepository.findBy({ const newAddressField = await this.fieldMetadataRepository.findBy({
workspaceId, workspaceId,
standardId: newFieldStandardId, standardId: newFieldStandardId,
@ -156,12 +157,6 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
`New address field successfully added to view ${viewId} for workspace ${workspaceId}`, `New address field successfully added to view ${viewId} for workspace ${workspaceId}`,
); );
} }
} catch (error) {
this.logger.log(
chalk.red(`Running command on workspace ${workspaceId} failed`),
);
throw error;
}
} }
} }
@ -170,8 +165,16 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
this.logger.log( this.logger.log(
chalk.green(`Running command on workspace ${workspaceId} done`), chalk.green(`Running command on workspace ${workspaceId} done`),
); );
} catch (error) {
this.logger.log(
chalk.red(
`Running command on workspace ${workspaceId} failed with error: ${error}`,
),
);
continue;
} }
this.logger.log(chalk.green(`Command completed!`)); this.logger.log(chalk.green(`Command completed!`));
} }
} }
}