From c9f56650e7087cb285bde72904dd1a6fc54ff8d3 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Wed, 28 Aug 2024 23:28:44 +0530 Subject: [PATCH] fix: load table even if formula error is present (#9299) Co-authored-by: mertmit --- packages/nc-gui/composables/useViewData.ts | 13 ++++++++++++- packages/nc-gui/store/tables.ts | 7 +++++++ .../src/db/formulav2/formulaQueryBuilderv2.ts | 5 +++-- packages/nocodb/src/helpers/catchError.ts | 9 +++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index 4541488922..7192f4b359 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -16,7 +16,8 @@ export function useViewData( viewMeta: Ref | ComputedRef<(ViewType & { id: string }) | undefined>, where?: ComputedRef, ) { - const { activeTableId, activeTable } = storeToRefs(useTablesStore()) + const tablesStore = useTablesStore() + const { activeTableId, activeTable } = storeToRefs(tablesStore) const meta = computed(() => _meta.value || activeTable.value) const metaId = computed(() => _meta.value?.id || activeTableId.value) @@ -199,6 +200,16 @@ export function useViewData( if (error.code === 'ERR_CANCELED') { return } + + // retry the request if the error is FORMULA_ERROR + if (error?.response?.data?.error === 'FORMULA_ERROR') { + message.error(await extractSdkResponseErrorMsg(error)) + + await tablesStore.reloadTableMeta(metaId.value as string) + + return loadData(params, shouldShowLoading) + } + console.error(error) return message.error(await extractSdkResponseErrorMsg(error)) } diff --git a/packages/nc-gui/store/tables.ts b/packages/nc-gui/store/tables.ts index b54b1445e9..3d21bcbcf4 100644 --- a/packages/nc-gui/store/tables.ts +++ b/packages/nc-gui/store/tables.ts @@ -228,6 +228,12 @@ export const useTablesStore = defineStore('tablesStore', () => { return url.href } + const reloadTableMeta = async (tableId: string) => { + const { getMeta } = useMetas() + + await getMeta(tableId, true) + } + return { baseTables, loadProjectTables, @@ -239,6 +245,7 @@ export const useTablesStore = defineStore('tablesStore', () => { activeTableId, navigateToTable, tableUrl, + reloadTableMeta, } }) diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index 893eed4374..35a8f3a2f1 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -23,6 +23,7 @@ import { convertDateFormatForConcat } from '~/helpers/formulaFnHelper'; import FormulaColumn from '~/models/FormulaColumn'; import { BaseUser, ButtonColumn } from '~/models'; import { getRefColumnIfAlias } from '~/helpers'; +import { ExternalTimeout, NcError } from '~/helpers/catchError'; const logger = new Logger('FormulaQueryBuilderv2'); @@ -1373,7 +1374,7 @@ export default async function formulaQueryBuilderv2( await NocoCache.update(`${CacheScope.COL_BUTTON}:${column.id}`, { error: e.message, }); - } else { + } else if (!(e instanceof ExternalTimeout)) { // add formula error to show in UI await FormulaColumn.update(context, column.id, { error: e.message, @@ -1385,7 +1386,7 @@ export default async function formulaQueryBuilderv2( }); } } - throw new Error(`Formula error: ${e.message}`); + NcError.formulaError(e.message); } return qb; } diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 9cf6fd9a10..7fc305ec87 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -484,6 +484,8 @@ export class ExternalError extends NcBaseError { } } +export class ExternalTimeout extends ExternalError {} + export class UnprocessableEntity extends NcBaseError {} export class AjvError extends NcBaseError { @@ -888,6 +890,13 @@ export class NcError { }); } + static formulaError(message: string, args?: NcErrorArgs) { + throw new NcBaseErrorv2(NcErrorType.FORMULA_ERROR, { + params: message, + ...args, + }); + } + static notFound(message = 'Not found') { throw new NotFound(message); }