From 033fd344b5a09a7b9c0b941279da1744e182cc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 31 Jan 2024 14:25:03 +0100 Subject: [PATCH] fix(core): Handle possibly invalid `updatedAt` timestamps in source-control (#8485) --- .../sourceControlImport.service.ee.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/environments/sourceControl/sourceControlImport.service.ee.ts b/packages/cli/src/environments/sourceControl/sourceControlImport.service.ee.ts index 2fe8525996..fb8e8d2207 100644 --- a/packages/cli/src/environments/sourceControl/sourceControlImport.service.ee.ts +++ b/packages/cli/src/environments/sourceControl/sourceControlImport.service.ee.ts @@ -8,7 +8,7 @@ import { SOURCE_CONTROL_WORKFLOW_EXPORT_FOLDER, } from './constants'; import glob from 'fast-glob'; -import { ApplicationError, jsonParse } from 'n8n-workflow'; +import { ApplicationError, jsonParse, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow'; import { readFile as fsReadFile } from 'fs/promises'; import { Credentials, InstanceSettings } from 'n8n-core'; import type { IWorkflowToImport } from '@/Interfaces'; @@ -87,14 +87,28 @@ export class SourceControlImportService { const localWorkflows = await Container.get(WorkflowRepository).find({ select: ['id', 'name', 'versionId', 'updatedAt'], }); - return localWorkflows.map((local) => ({ - id: local.id, - versionId: local.versionId, - name: local.name, - localId: local.id, - filename: getWorkflowExportPath(local.id, this.workflowExportFolder), - updatedAt: local.updatedAt.toISOString(), - })) as SourceControlWorkflowVersionId[]; + return localWorkflows.map((local) => { + let updatedAt: Date; + if (local.updatedAt instanceof Date) { + updatedAt = local.updatedAt; + } else { + ErrorReporter.warn('updatedAt is not a Date', { + extra: { + type: typeof local.updatedAt, + value: local.updatedAt, + }, + }); + updatedAt = isNaN(Date.parse(local.updatedAt)) ? new Date() : new Date(local.updatedAt); + } + return { + id: local.id, + versionId: local.versionId, + name: local.name, + localId: local.id, + filename: getWorkflowExportPath(local.id, this.workflowExportFolder), + updatedAt: updatedAt.toISOString(), + }; + }) as SourceControlWorkflowVersionId[]; } public async getRemoteCredentialsFromFiles(): Promise<