fix: make errors in build_flow function use the standardized ErrorMessage schema (#5199)
* fix: enhance error handling in build_flow function by utilizing ErrorMessage schema - Introduced ErrorMessage schema to standardize error reporting in the build_flow function. - Updated error handling to include flow_id, session_id, and trace_name for better context in error messages. - Improved clarity and maintainability of error handling logic across multiple exception cases. * Remove session_id from ErrorMessage in chat endpoint * fix: enhance error handling in build_flow function by checking for custom component existence Updated the error handling logic in the build_flow function to safely access the trace_name of the custom component. This change ensures that if the custom component is not present, the trace_name will be set to None, improving the robustness of error reporting. * fix: update ErrorMessage schema to allow optional session_id and source - Modified the ErrorMessage class to accept optional parameters for session_id and source, enhancing flexibility in error reporting. - Updated the initialization logic to handle None values for sender and component attributes, ensuring robustness in cases where source may not be provided. * fix: improve error handling in build_flow function by using getattr for trace_name Updated the error handling logic in the build_flow function to utilize getattr for safely accessing the trace_name attribute of the custom component. This change ensures that if the custom component is not present, trace_name will default to None, enhancing the robustness of error reporting.
This commit is contained in:
parent
40d179ddc4
commit
d41d740768
2 changed files with 26 additions and 15 deletions
|
|
@ -39,6 +39,7 @@ from langflow.events.event_manager import EventManager, create_default_event_man
|
||||||
from langflow.exceptions.component import ComponentBuildError
|
from langflow.exceptions.component import ComponentBuildError
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.graph.utils import log_vertex_build
|
from langflow.graph.utils import log_vertex_build
|
||||||
|
from langflow.schema.message import ErrorMessage
|
||||||
from langflow.schema.schema import OutputValue
|
from langflow.schema.schema import OutputValue
|
||||||
from langflow.services.cache.utils import CacheMiss
|
from langflow.services.cache.utils import CacheMiss
|
||||||
from langflow.services.chat.service import ChatService
|
from langflow.services.chat.service import ChatService
|
||||||
|
|
@ -376,10 +377,11 @@ async def build_flow(
|
||||||
vertices_task.cancel()
|
vertices_task.cancel()
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, HTTPException):
|
error_message = ErrorMessage(
|
||||||
event_manager.on_error(data={"error": str(e.detail), "statusCode": e.status_code})
|
flow_id=flow_id,
|
||||||
raise
|
exception=e,
|
||||||
event_manager.on_error(data={"error": str(e)})
|
)
|
||||||
|
event_manager.on_error(data=error_message.data)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
ids, vertices_to_run, graph = vertices_task.result()
|
ids, vertices_to_run, graph = vertices_task.result()
|
||||||
|
|
@ -387,10 +389,11 @@ async def build_flow(
|
||||||
try:
|
try:
|
||||||
ids, vertices_to_run, graph = await build_graph_and_get_order()
|
ids, vertices_to_run, graph = await build_graph_and_get_order()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, HTTPException):
|
error_message = ErrorMessage(
|
||||||
event_manager.on_error(data={"error": str(e.detail), "statusCode": e.status_code})
|
flow_id=flow_id,
|
||||||
raise
|
exception=e,
|
||||||
event_manager.on_error(data={"error": str(e)})
|
)
|
||||||
|
event_manager.on_error(data=error_message.data)
|
||||||
raise
|
raise
|
||||||
event_manager.on_vertices_sorted(data={"ids": ids, "to_run": vertices_to_run})
|
event_manager.on_vertices_sorted(data={"ids": ids, "to_run": vertices_to_run})
|
||||||
await client_consumed_queue.get()
|
await client_consumed_queue.get()
|
||||||
|
|
@ -408,7 +411,15 @@ async def build_flow(
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error building vertices: {e}")
|
logger.error(f"Error building vertices: {e}")
|
||||||
event_manager.on_error(data={"error": str(e)})
|
custom_component = graph.get_vertex(vertex_id).custom_component
|
||||||
|
trace_name = getattr(custom_component, "trace_name", None)
|
||||||
|
error_message = ErrorMessage(
|
||||||
|
flow_id=flow_id,
|
||||||
|
exception=e,
|
||||||
|
session_id=graph.session_id,
|
||||||
|
trace_name=trace_name,
|
||||||
|
)
|
||||||
|
event_manager.on_error(data=error_message.data)
|
||||||
raise
|
raise
|
||||||
event_manager.on_end(data={})
|
event_manager.on_end(data={})
|
||||||
await event_manager.queue.put((None, None, time.time))
|
await event_manager.queue.put((None, None, time.time))
|
||||||
|
|
|
||||||
|
|
@ -371,10 +371,10 @@ class ErrorMessage(Message):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
exception: BaseException,
|
exception: BaseException,
|
||||||
session_id: str,
|
session_id: str | None = None,
|
||||||
source: Source,
|
source: Source | None = None,
|
||||||
trace_name: str | None = None,
|
trace_name: str | None = None,
|
||||||
flow_id: str | None = None,
|
flow_id: UUID | str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
# This is done to avoid circular imports
|
# This is done to avoid circular imports
|
||||||
if exception.__class__.__name__ == "ExceptionWithMessageError" and exception.__cause__ is not None:
|
if exception.__class__.__name__ == "ExceptionWithMessageError" and exception.__cause__ is not None:
|
||||||
|
|
@ -400,8 +400,8 @@ class ErrorMessage(Message):
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
sender=source.display_name,
|
sender=source.display_name if source else None,
|
||||||
sender_name=source.display_name,
|
sender_name=source.display_name if source else None,
|
||||||
text=reason,
|
text=reason,
|
||||||
properties=Properties(
|
properties=Properties(
|
||||||
text_color="red",
|
text_color="red",
|
||||||
|
|
@ -420,7 +420,7 @@ class ErrorMessage(Message):
|
||||||
contents=[
|
contents=[
|
||||||
ErrorContent(
|
ErrorContent(
|
||||||
type="error",
|
type="error",
|
||||||
component=source.display_name,
|
component=source.display_name if source else None,
|
||||||
field=str(exception.field) if hasattr(exception, "field") else None,
|
field=str(exception.field) if hasattr(exception, "field") else None,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
solution=str(exception.solution) if hasattr(exception, "solution") else None,
|
solution=str(exception.solution) if hasattr(exception, "solution") else None,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue