From a2f98af534be52f12b7b0e9007c239976febb5b0 Mon Sep 17 00:00:00 2001 From: mertmit Date: Thu, 17 Oct 2024 23:03:55 +0300 Subject: [PATCH] fix: properly throw formula errors Signed-off-by: mertmit --- packages/nocodb/src/helpers/catchError.ts | 9 ++++++++- packages/nocodb/src/services/columns.service.ts | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 7fc305ec87..1cf89641b6 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -636,7 +636,14 @@ const errorHelpers: { code: 400, }, [NcErrorType.FORMULA_ERROR]: { - message: (message: string) => `Formula error: ${message}`, + message: (message: string) => { + // try to extract db error - Experimental + if (message.includes(' - ')) { + const [_, dbError] = message.split(' - '); + return `Formula error: ${dbError}`; + } + return `Formula error: ${message}`; + }, code: 400, }, [NcErrorType.PERMISSION_DENIED]: { diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 1668774fad..472b44d4fc 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -388,7 +388,7 @@ export class ColumnsService { ); } catch (e) { console.error(e); - NcError.badRequest('Invalid Formula'); + throw e; } await Column.update(context, column.id, { @@ -1802,7 +1802,7 @@ export class ColumnsService { ); } catch (e) { console.error(e); - NcError.badRequest('Invalid Formula'); + throw e; } await Column.insert(context, {