From 4a22be0c0e4d0f7820a4deba422c828935036154 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Thu, 19 Dec 2024 21:22:28 +0200 Subject: [PATCH] Throw an error when using the name of a non-existent collection. --- .../CollectionComponent.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts b/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts index bdfeef199..c2b6d5e5e 100644 --- a/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts +++ b/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts @@ -151,17 +151,18 @@ function resolveBlockValues(context: any, block: any): any { const collectionItem = blockValue.collection_name ? context[blockValue.collection_name] : innerMostCollectionItem; - if (!collectionItem) continue; - - switch (blockValue.variable_type) { - case 'current_item': - clonedBlock[key] = blockValue.path - ? resolvePathValue(collectionItem.current_item, blockValue.path) - : JSON.stringify(collectionItem.current_item); - break; - default: - clonedBlock[key] = collectionItem[blockValue.variable_type]; - break; + if (!collectionItem) { + throw new Error( + `Collection not found: ${blockValue.collection_name || 'default collection'}` + ); + } + + if (blockValue.variable_type === 'current_item') { + clonedBlock[key] = blockValue.path + ? resolvePathValue(collectionItem.current_item, blockValue.path) + : JSON.stringify(collectionItem.current_item); + } else { + clonedBlock[key] = collectionItem[blockValue.variable_type]; } } else if (Array.isArray(blockValue)) { // Resolve each item in the array