From 733f7c709d949906cdb7ec9c83bf26fc15484609 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 18 Nov 2023 12:10:33 +0530 Subject: [PATCH 1/2] refactor: uniform error message --- packages/nocodb/src/db/BaseModelSqlv2.ts | 4 ++-- packages/nocodb/src/db/conditionV2.ts | 2 +- packages/nocodb/src/db/generateLookupSelectQuery.ts | 2 +- packages/nocodb/src/db/sortV2.ts | 2 +- packages/nocodb/src/helpers/catchError.ts | 2 +- packages/nocodb/src/helpers/getAst.ts | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 97b0de29dc..90a83914f1 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5195,7 +5195,7 @@ export function extractSortsObject( if (throwErrorIfInvalid && !sort.fk_column_id) NcError.unprocessableEntity( - `Invalid column '${s.replace(/^[+-]/, '')}' in sort`, + `Invalid field '${s.replace(/^[+-]/, '')}' in sort`, ); return new Sort(sort); @@ -5360,7 +5360,7 @@ export function extractCondition( validateFilterComparison(aliasColObjMap[alias].uidt, op, sub_op); } else if (throwErrorIfInvalid) { - NcError.unprocessableEntity(`Column '${alias}' not found.`); + NcError.unprocessableEntity(`Invalid field '${alias}' in Query`); } return new Filter({ diff --git a/packages/nocodb/src/db/conditionV2.ts b/packages/nocodb/src/db/conditionV2.ts index 2cee6d72c6..fa6104cdc8 100644 --- a/packages/nocodb/src/db/conditionV2.ts +++ b/packages/nocodb/src/db/conditionV2.ts @@ -156,7 +156,7 @@ const parseConditionV2 = async ( if (!column) { if (throwErrorIfInvalid) { NcError.unprocessableEntity( - `Invalid column id '${filter.fk_column_id}' in filter`, + `Invalid field ID '${filter.fk_column_id}' in Query`, ); } return; diff --git a/packages/nocodb/src/db/generateLookupSelectQuery.ts b/packages/nocodb/src/db/generateLookupSelectQuery.ts index 09187d1fdc..758b5894db 100644 --- a/packages/nocodb/src/db/generateLookupSelectQuery.ts +++ b/packages/nocodb/src/db/generateLookupSelectQuery.ts @@ -54,7 +54,7 @@ export default async function generateLookupSelectQuery({ if (column.uidt === UITypes.Lookup) { lookupColOpt = await column.getColOptions(); } else if (column.uidt !== UITypes.LinkToAnotherRecord) { - NcError.badRequest('Invalid column type'); + NcError.badRequest('Invalid field type'); } await column.getColOptions(); diff --git a/packages/nocodb/src/db/sortV2.ts b/packages/nocodb/src/db/sortV2.ts index 05f36dde69..949b9799e6 100644 --- a/packages/nocodb/src/db/sortV2.ts +++ b/packages/nocodb/src/db/sortV2.ts @@ -37,7 +37,7 @@ export default async function sortV2( if (!column) { if (throwErrorIfInvalid) { NcError.unprocessableEntity( - `Invalid column id '${sort.fk_column_id}' in sort`, + `Invalid field ID '${sort.fk_column_id}' in Query`, ); } continue; diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 0cb8109447..0d4e4060d7 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -324,7 +324,7 @@ export function extractDBError(error): { / Invalid object name '(\w+)'./i, ); const extractMissingColMatch = error.message.match( - / Invalid column name '(\w+)'./i, + / Invalid field '(\w+)'./i, ); if (extractTableNameMatch && extractTableNameMatch[1]) { diff --git a/packages/nocodb/src/helpers/getAst.ts b/packages/nocodb/src/helpers/getAst.ts index 95eb299177..bbe05d0d9c 100644 --- a/packages/nocodb/src/helpers/getAst.ts +++ b/packages/nocodb/src/helpers/getAst.ts @@ -74,7 +74,7 @@ const getAst = async ({ ); if (invalidFields.length) { NcError.unprocessableEntity( - `Following fields are invalid: ${invalidFields.join(', ')}`, + `Invalid field '${invalidFields[0]}' in Query`, ); } } From bbde7bba0b795cd9c4116b363dea26e26aa780f3 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Sat, 18 Nov 2023 22:16:49 +0530 Subject: [PATCH 2/2] fix: error strings Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- packages/nocodb/src/db/BaseModelSqlv2.ts | 6 ++---- packages/nocodb/src/db/conditionV2.ts | 4 +--- packages/nocodb/src/db/sortV2.ts | 4 +--- packages/nocodb/src/helpers/catchError.ts | 2 +- packages/nocodb/src/helpers/getAst.ts | 4 +--- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 90a83914f1..a4fdf92257 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5194,9 +5194,7 @@ export function extractSortsObject( else sort.fk_column_id = aliasColObjMap[s.replace(/^\+/, '')]?.id; if (throwErrorIfInvalid && !sort.fk_column_id) - NcError.unprocessableEntity( - `Invalid field '${s.replace(/^[+-]/, '')}' in sort`, - ); + NcError.unprocessableEntity(`Invalid field: ${s.replace(/^[+-]/, '')}`); return new Sort(sort); }); @@ -5360,7 +5358,7 @@ export function extractCondition( validateFilterComparison(aliasColObjMap[alias].uidt, op, sub_op); } else if (throwErrorIfInvalid) { - NcError.unprocessableEntity(`Invalid field '${alias}' in Query`); + NcError.unprocessableEntity(`Invalid field: ${alias}`); } return new Filter({ diff --git a/packages/nocodb/src/db/conditionV2.ts b/packages/nocodb/src/db/conditionV2.ts index fa6104cdc8..2dd71f9658 100644 --- a/packages/nocodb/src/db/conditionV2.ts +++ b/packages/nocodb/src/db/conditionV2.ts @@ -155,9 +155,7 @@ const parseConditionV2 = async ( const column = await filter.getColumn(); if (!column) { if (throwErrorIfInvalid) { - NcError.unprocessableEntity( - `Invalid field ID '${filter.fk_column_id}' in Query`, - ); + NcError.unprocessableEntity(`Invalid field: ${filter.fk_column_id}`); } return; } diff --git a/packages/nocodb/src/db/sortV2.ts b/packages/nocodb/src/db/sortV2.ts index 949b9799e6..0871c6c870 100644 --- a/packages/nocodb/src/db/sortV2.ts +++ b/packages/nocodb/src/db/sortV2.ts @@ -36,9 +36,7 @@ export default async function sortV2( const column = await sort.getColumn(); if (!column) { if (throwErrorIfInvalid) { - NcError.unprocessableEntity( - `Invalid field ID '${sort.fk_column_id}' in Query`, - ); + NcError.unprocessableEntity(`Invalid field: ${sort.fk_column_id}`); } continue; } diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 0d4e4060d7..0ec0af1e77 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -324,7 +324,7 @@ export function extractDBError(error): { / Invalid object name '(\w+)'./i, ); const extractMissingColMatch = error.message.match( - / Invalid field '(\w+)'./i, + / Invalid field: (\w+)./i, ); if (extractTableNameMatch && extractTableNameMatch[1]) { diff --git a/packages/nocodb/src/helpers/getAst.ts b/packages/nocodb/src/helpers/getAst.ts index bbe05d0d9c..905ff35eba 100644 --- a/packages/nocodb/src/helpers/getAst.ts +++ b/packages/nocodb/src/helpers/getAst.ts @@ -73,9 +73,7 @@ const getAst = async ({ (f) => !colAliasMap[f] && !aliasColMap[f], ); if (invalidFields.length) { - NcError.unprocessableEntity( - `Invalid field '${invalidFields[0]}' in Query`, - ); + NcError.unprocessableEntity(`Invalid field: ${invalidFields[0]}`); } } } else {