From bdac4c81f7029fada9ecc79a16fa5dcdba5cff89 Mon Sep 17 00:00:00 2001 From: Weiko Date: Fri, 9 Aug 2024 16:23:14 +0200 Subject: [PATCH] Improve QueryFailedError message in sync-metadata (#6591) Adding more logs with Typeorm QueryFailedError in sync-metadata command Example with a unicity constraint violation, to identify which column is affected Screenshot 2024-08-09 at 14 56 05 In this case, this should help self-hosting users to know which key is a duplicate during syncs after a version upgrade for example --- .../workspace-sync-metadata.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service.ts index 117ca1e591..2a22bac596 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service.ts @@ -1,7 +1,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { InjectDataSource } from '@nestjs/typeorm'; -import { DataSource } from 'typeorm'; +import { DataSource, QueryFailedError } from 'typeorm'; import { WorkspaceSyncContext } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/workspace-sync-context.interface'; @@ -150,6 +150,10 @@ export class WorkspaceSyncMetadataService { ); } catch (error) { this.logger.error('Sync of standard objects failed with:', error); + + if (error instanceof QueryFailedError && (error as any).detail) { + this.logger.error((error as any).detail); + } await queryRunner.rollbackTransaction(); } finally { await queryRunner.release();