From 6a433945a3f11845c940c6587a417a8b5dc9464d Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 19 Sep 2023 15:42:07 +0300 Subject: [PATCH] fix: handle async error for streamModelDataAsCsv Signed-off-by: mertmit --- .../jobs/export-import/duplicate.processor.ts | 54 +++++++++++++------ .../jobs/jobs/export-import/export.service.ts | 9 ++++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts index e8d2333fe7..11fba4786b 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts @@ -242,7 +242,11 @@ export class DuplicateProcessor { let handledLinks = []; + let error = null; + for (const sourceModel of sourceModels) { + if (error) break; + const dataStream = new Readable({ read() {}, }); @@ -251,13 +255,20 @@ export class DuplicateProcessor { read() {}, }); - this.exportService.streamModelDataAsCsv({ - dataStream, - linkStream, - projectId: sourceProject.id, - modelId: sourceModel.id, - handledMmList: handledLinks, - }); + this.exportService + .streamModelDataAsCsv({ + dataStream, + linkStream, + projectId: sourceProject.id, + modelId: sourceModel.id, + handledMmList: handledLinks, + }) + .catch((e) => { + this.logger.error(e); + dataStream.push(null); + linkStream.push(null); + error = e; + }); const model = await Model.get(findWithIdentifier(idMap, sourceModel.id)); @@ -284,6 +295,8 @@ export class DuplicateProcessor { ); } + if (error) throw error; + // update external models (has bt to this model) if (externalModels) { for (const sourceModel of externalModels) { @@ -299,14 +312,23 @@ export class DuplicateProcessor { read() {}, }); - this.exportService.streamModelDataAsCsv({ - dataStream, - linkStream, - projectId: sourceProject.id, - modelId: sourceModel.id, - handledMmList: handledLinks, - _fieldIds: fields, - }); + let error = null; + + this.exportService + .streamModelDataAsCsv({ + dataStream, + linkStream, + projectId: sourceProject.id, + modelId: sourceModel.id, + handledMmList: handledLinks, + _fieldIds: fields, + }) + .catch((e) => { + this.logger.error(e); + dataStream.push(null); + linkStream.push(null); + error = e; + }); const headers: string[] = []; let chunk = []; @@ -401,6 +423,8 @@ export class DuplicateProcessor { }); }); + if (error) throw error; + elapsedTime( hrTime, `map existing links to ${model.title}`, diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts index d0c6814070..b404789727 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts @@ -722,15 +722,24 @@ export class ExportService { dataStream, ); + let error = null; + this.streamModelDataAsCsv({ dataStream, linkStream, projectId: project.id, modelId: model.id, handledMmList, + }).catch((e) => { + this.logger.error(e); + dataStream.push(null); + linkStream.push(null); + error = e; }); await Promise.all([uploadPromise, linkPromise]); + + if (error) throw error; } combinedLinkStream.push(null);