From d0484ba41212f259b40a01e9fc9abafc75695c5b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 9 Aug 2024 11:15:35 -0300 Subject: [PATCH] fix: enhance error handling in build_flow and add error handling for Flow build (#3259) * feat: add error handling for Flow build The code changes in `buildUtils.ts` add error handling for the Flow build process. It includes a new case for handling errors in the switch statement, which displays the error message and triggers the `onBuildError` function. This change ensures that errors during the Flow build are properly handled and the build process is stopped. * feat: enhance error handling in build_flow to capture and report HTTP exceptions in the flow building process --- src/backend/base/langflow/api/v1/chat.py | 15 ++++++++++++++- src/frontend/src/utils/buildUtils.ts | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/api/v1/chat.py b/src/backend/base/langflow/api/v1/chat.py index 143937d1d..49bf23410 100644 --- a/src/backend/base/langflow/api/v1/chat.py +++ b/src/backend/base/langflow/api/v1/chat.py @@ -356,10 +356,23 @@ async def build_flow( except asyncio.CancelledError: vertices_task.cancel() return + except Exception as e: + if isinstance(e, HTTPException): + send_event("error", {"error": str(e.detail), "statusCode": e.status_code}, queue) + raise e + send_event("error", {"error": str(e)}, queue) + raise e ids, vertices_to_run, graph = vertices_task.result() else: - ids, vertices_to_run, graph = await build_graph_and_get_order() + try: + ids, vertices_to_run, graph = await build_graph_and_get_order() + except Exception as e: + if isinstance(e, HTTPException): + send_event("error", {"error": str(e.detail), "statusCode": e.status_code}, queue) + raise e + send_event("error", {"error": str(e)}, queue) + raise e send_event("vertices_sorted", {"ids": ids, "to_run": vertices_to_run}, queue) await client_consumed_queue.get() diff --git a/src/frontend/src/utils/buildUtils.ts b/src/frontend/src/utils/buildUtils.ts index 969138598..77dbb8054 100644 --- a/src/frontend/src/utils/buildUtils.ts +++ b/src/frontend/src/utils/buildUtils.ts @@ -264,6 +264,14 @@ export async function buildFlowVertices({ useFlowStore.getState().setIsBuilding(false); return true; } + case "error": { + const errorMessage = data.error; + console.log(data); + onBuildError!("Error Running Flow", [errorMessage], []); + buildResults.push(false); + useFlowStore.getState().setIsBuilding(false); + return true; + } default: return true; }