Browse Source

Merge pull request #5154 from nocodb/refactor/upgrade-timeout-msg

feat: upgrade timeout msg
pull/5162/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
ea24fa9121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts
  2. 10
      packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts
  3. 27
      packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts

10
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
@ -170,6 +177,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
} catch (e) {
// 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;
}
}

10
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
@ -151,6 +158,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
} catch (e) {
// 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;
}
}

27
packages/nocodb/src/lib/version-upgrader/ncUpgradeErrors.ts

@ -0,0 +1,27 @@
export function throwTimeoutError(e, timeoutErrorInfo) {
if (
[
'EHOSTDOWN',
'ETIMEDOUT',
'EHOSTUNREACH',
'ENOTFOUND',
'ECONNREFUSED',
].includes(e.code)
) {
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.`
);
}
}
Loading…
Cancel
Save