From b4dbe90212a1ea8e64e29b25738b67210a1f7702 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Tue, 20 Feb 2024 15:08:19 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(buildUtils.ts):=20refactor?= =?UTF-8?q?=20buildVertices=20function=20to=20improve=20readability=20and?= =?UTF-8?q?=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The buildVertices function has been refactored to improve readability and error handling. Instead of using Promise.all with map, it now uses a for loop to iterate over the vertices and perform the build process for each vertex. This change allows for better error handling and reporting. Additionally, the onBuildError callback is now called with the correct parameters when there is an error building a component. --- src/frontend/src/utils/buildUtils.ts | 54 ++++++++++++---------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/frontend/src/utils/buildUtils.ts b/src/frontend/src/utils/buildUtils.ts index 854a86f24..26a225733 100644 --- a/src/frontend/src/utils/buildUtils.ts +++ b/src/frontend/src/utils/buildUtils.ts @@ -52,42 +52,34 @@ export async function buildVertices({ const buildResults: Array = []; for (let i = 0; i < vertices.length; i += 1) { if (onBuildStart) onBuildStart(vertices[i]); - await Promise.all( - vertices[i].map(async (id) => { - try { - // Set vertex state to building - const buildRes = await postBuildVertex(flowId, id); - const buildData: VertexBuildTypeAPI = buildRes.data; - if (onBuildUpdate) { - let data = {}; - if (!buildData.valid) { - if (onBuildError) { - onBuildError( - "Error Building Component", - [buildData.params], - verticesIds - ); - } - } - data[buildData.id] = buildData; - onBuildUpdate({ data, id: buildData.id }); - } - buildResults.push(buildData.valid); - } catch (error) { - if (onBuildError) { - console.log(error); - onBuildError( + for (const id of vertices[i]) { + try { + const buildRes = await postBuildVertex(flowId, id); + const buildData: VertexBuildTypeAPI = buildRes.data; + if (onBuildUpdate) { + let data = {}; + if (!buildData.valid) { + onBuildError!( "Error Building Component", - [ - (error as AxiosError).response?.data?.detail ?? - "Unknown Error", - ], + [buildData.params], verticesIds ); } + data[buildData.id] = buildData; + onBuildUpdate({ data, id: buildData.id }); } - }) - ); + buildResults.push(buildData.valid); + } catch (error) { + onBuildError!( + "Error Building Component", + [ + (error as AxiosError).response?.data?.detail ?? + "Unknown Error", + ], + verticesIds + ); + } + } } if (onBuildComplete) { const allNodesValid = buildResults.every((result) => result);