From d7b6820aa27039e9496b578786f0ff9ec9b3d6fe Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 18 Feb 2023 18:20:29 +0800 Subject: [PATCH 1/5] feat(nocodb): add ncUpgradeError --- .../lib/version-upgrader/ncUpgradeErrors.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts diff --git a/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts b/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts new file mode 100644 index 0000000000..dd278404c1 --- /dev/null +++ b/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts @@ -0,0 +1,19 @@ +export function throwTimeoutError(e, timeoutErrorInfo) { + if (e.code === 'ETIMEDOUT') { + let db = ''; + if (timeoutErrorInfo.connection.filename) { + // for sqlite + db = timeoutErrorInfo.connection.filename; + } else if ( + timeoutErrorInfo.connection.database && + timeoutErrorInfo.connection.host && + timeoutErrorInfo.connection.port + ) { + db = `${timeoutErrorInfo.connection.database} (${timeoutErrorInfo.connection.host}:${timeoutErrorInfo.connection.port})`; + } + throw new Error( + `Failed to connect the database ${db} for Project ${timeoutErrorInfo.projectTitle}. + Please fix the connection issue or remove the project before trying to upgrade.` + ); + } +} From 6012549ad92e2178ce92ea0fac91d03a18a3213a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 18 Feb 2023 18:21:05 +0800 Subject: [PATCH 2/5] feat(nocodb): throw timeout error for connecting to external data dbs --- .../src/lib/version-upgrader/ncAttachmentUpgrader.ts | 10 ++++++++++ .../version-upgrader/ncAttachmentUpgrader_0104002.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts index a66cae4359..e835ed9606 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts @@ -6,6 +6,7 @@ import Model from '../models/Model'; import { XKnex } from '../db/sql-data-mapper/index'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; import { BaseType, UITypes } from 'nocodb-sdk'; +import { throwTimeoutError } from './ncUpgradeErrors'; // before 0.103.0, an attachment object was like // [{ @@ -68,6 +69,12 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { : NcConnectionMgrv2.get(base); const models = await base.getModels(ncMeta); + // used in timeout error message + const timeoutErrorInfo = { + projectTitle: project.title, + connection: knex.client.config.connection, + }; + for (const model of models) { try { // if the table is missing in database, skip @@ -168,6 +175,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { } await Promise.all(updateRecords); } catch (e) { + // throw the custom timeout error message if applicable + throwTimeoutError(e, timeoutErrorInfo); + // ignore the error related to deleted project if (!isProjectDeleted) { throw e; diff --git a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts index 3531b296c9..7843329cdf 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts @@ -6,6 +6,7 @@ import Model from '../models/Model'; import { XKnex } from '../db/sql-data-mapper/index'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; import { BaseType, UITypes } from 'nocodb-sdk'; +import { throwTimeoutError } from './ncUpgradeErrors'; // after 0101002 upgrader, the attachment object would become broken when // (1) switching views after updating a singleSelect field @@ -60,6 +61,12 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { : NcConnectionMgrv2.get(base); const models = await base.getModels(ncMeta); + // used in timeout error message + const timeoutErrorInfo = { + projectTitle: project.title, + connection: knex.client.config.connection, + }; + for (const model of models) { try { // if the table is missing in database, skip @@ -149,6 +156,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { } await Promise.all(updateRecords); } catch (e) { + // throw the custom timeout error message if applicable + throwTimeoutError(e, timeoutErrorInfo); + // ignore the error related to deleted project if (!isProjectDeleted) { throw e; From e9449458552f26f47afde59af6e0f00a7d2b5a51 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 18 Feb 2023 18:50:02 +0800 Subject: [PATCH 3/5] refactor(nocodb): move to !isProjectDeleted case --- .../nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts | 6 +++--- .../lib/version-upgrader/ncAttachmentUpgrader_0104002.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts index e835ed9606..f5c1393b3a 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts @@ -175,11 +175,11 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { } await Promise.all(updateRecords); } catch (e) { - // throw the custom timeout error message if applicable - throwTimeoutError(e, timeoutErrorInfo); - // ignore the error related to deleted project if (!isProjectDeleted) { + // throw the custom timeout error message if applicable + throwTimeoutError(e, timeoutErrorInfo); + // throw general error throw e; } } diff --git a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts index 7843329cdf..cb47f72122 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts @@ -156,11 +156,11 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { } await Promise.all(updateRecords); } catch (e) { - // throw the custom timeout error message if applicable - throwTimeoutError(e, timeoutErrorInfo); - // ignore the error related to deleted project if (!isProjectDeleted) { + // throw the custom timeout error message if applicable + throwTimeoutError(e, timeoutErrorInfo); + // throw general error throw e; } } From d9b1ba77fcf0e7a837434dc5563c7986aee19057 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 18 Feb 2023 18:50:20 +0800 Subject: [PATCH 4/5] feat(nocodb): include 'EHOSTDOWN' and 'EHOSTUNREACH' --- packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts b/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts index dd278404c1..54f84b6af7 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts @@ -1,5 +1,5 @@ export function throwTimeoutError(e, timeoutErrorInfo) { - if (e.code === 'ETIMEDOUT') { + if (['EHOSTDOWN', 'ETIMEDOUT', 'EHOSTUNREACH'].includes(e.code)) { let db = ''; if (timeoutErrorInfo.connection.filename) { // for sqlite From 5ad3d50485349b1ce1c2e430fa2c9fe4c452c88e Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 18 Feb 2023 19:05:50 +0800 Subject: [PATCH 5/5] feat(nocodb): add ENOTFOUND & ECONNREFUSED --- .../nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts b/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts index 54f84b6af7..3b9b7330ab 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts @@ -1,5 +1,13 @@ export function throwTimeoutError(e, timeoutErrorInfo) { - if (['EHOSTDOWN', 'ETIMEDOUT', 'EHOSTUNREACH'].includes(e.code)) { + if ( + [ + 'EHOSTDOWN', + 'ETIMEDOUT', + 'EHOSTUNREACH', + 'ENOTFOUND', + 'ECONNREFUSED', + ].includes(e.code) + ) { let db = ''; if (timeoutErrorInfo.connection.filename) { // for sqlite