From 0757fd0e1feed0483f97bb06747c95d05bb4b971 Mon Sep 17 00:00:00 2001 From: chetan-contentstack Date: Mon, 27 Jul 2026 15:10:05 +0530 Subject: [PATCH 1/3] fix: improve file writing and ensure asset directory creation --- api/src/services/contentful.service.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/api/src/services/contentful.service.ts b/api/src/services/contentful.service.ts index df1f88508..4cb46106c 100644 --- a/api/src/services/contentful.service.ts +++ b/api/src/services/contentful.service.ts @@ -335,11 +335,7 @@ async function readFile(filePath: string, fileName: string) { * @throws {Error} - If there is an error writing the file. */ async function writeOneFile(indexPath: string, fileMeta: any) { - fs.writeFile(indexPath, JSON.stringify(fileMeta), (err) => { - if (err) { - console.error("Error writing file: 3", err); - } - }); + await fs.promises.writeFile(indexPath, JSON.stringify(fileMeta)); } /** @@ -798,6 +794,7 @@ const createAssets = async (packagePath: any, destination_stack_id: string, proj ); await Promise.all(tasks); + await fs.promises.mkdir(assetsSave, { recursive: true }); const assetMasterFolderPath = path.join(assetsSave, ASSETS_FAILED_FILE); await writeOneFile(path.join(assetsSave, ASSETS_SCHEMA_FILE), assetData); From 86c00d7dd31afb3e2c51506656d6ee6f5dcc9781 Mon Sep 17 00:00:00 2001 From: chetan-contentstack Date: Tue, 28 Jul 2026 11:35:38 +0530 Subject: [PATCH 2/3] fix(contentful): rethrow from createAssets so write failures surface --- api/src/services/contentful.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/services/contentful.service.ts b/api/src/services/contentful.service.ts index 4cb46106c..070d89f67 100644 --- a/api/src/services/contentful.service.ts +++ b/api/src/services/contentful.service.ts @@ -830,6 +830,7 @@ const createAssets = async (packagePath: any, destination_stack_id: string, proj err ) await customLogger(projectId, destination_stack_id, 'error', message); + throw err; } }; From 1fc4e409baf0c70876c34c5f6d882abf12dc77f7 Mon Sep 17 00:00:00 2001 From: chetan-contentstack Date: Tue, 28 Jul 2026 12:08:29 +0530 Subject: [PATCH 3/3] fix: attach catch on fire-and-forget migration calls to prevent unhandled rejection --- api/src/controllers/migration.controller.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/src/controllers/migration.controller.ts b/api/src/controllers/migration.controller.ts index 1c03631fc..c90c7b6b1 100644 --- a/api/src/controllers/migration.controller.ts +++ b/api/src/controllers/migration.controller.ts @@ -25,6 +25,9 @@ const getAuditData = async (req: Request, res: Response): Promise => { */ const startTestMigration = async (req: Request, res: Response): Promise => { const resp = migrationService.startTestMigration(req); + Promise.resolve(resp).catch((err) => { + console.error('startTestMigration failed', err); + }); res.status(200).json(resp); }; @@ -38,6 +41,9 @@ const startTestMigration = async (req: Request, res: Response): Promise => */ const startMigration = async (req: Request, res: Response): Promise => { const resp = migrationService.startMigration(req); + Promise.resolve(resp).catch((err) => { + console.error('startMigration failed', err); + }); res.status(200).json(resp); };