From d579257f0d240a4e31371643cbb1029d9854a93a Mon Sep 17 00:00:00 2001 From: gustavoschaedler Date: Fri, 28 Jul 2023 01:21:05 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20handle=20except?= =?UTF-8?q?ions=20when=20getting=20custom=20function=20and=20building=20fi?= =?UTF-8?q?eld=20config=20to=20prevent=20crashes=20and=20log=20errors=20?= =?UTF-8?q?=E2=9C=A8=20feat(types.py):=20add=20validation=20check=20for=20?= =?UTF-8?q?custom=20component=20before=20building=20field=20config=20to=20?= =?UTF-8?q?ensure=20only=20valid=20components=20are=20processed=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20handle=20empty=20function=5Farg?= =?UTF-8?q?s=20case=20to=20prevent=20errors=20when=20adding=20extra=20fiel?= =?UTF-8?q?ds=20to=20the=20frontend=20node=20=F0=9F=90=9B=20fix(types.py):?= =?UTF-8?q?=20handle=20exceptions=20when=20creating=20custom=20component?= =?UTF-8?q?=20to=20prevent=20crashes=20and=20log=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/types.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index c6a901baa..52d7666c0 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -186,21 +186,28 @@ def update_display_name_and_description(frontend_node, template_config): frontend_node["description"] = template_config["description"] -def build_field_config(custom_component): +def build_field_config(custom_component: CustomComponent): """Build the field configuration for a custom component""" + is_valid = custom_component.is_check_valid() + try: custom_class = get_function_custom(custom_component.code) - return custom_class().build_config() - except Exception as exc: - logger.error(f"Error while building field config: {exc}") + logger.error(f"Error while getting custom function: {str(exc)}") + return {} + + try: + return custom_class().build_config() + except Exception as exc: + logger.error(f"Error while building field config: {str(exc)}") return {} def add_extra_fields(frontend_node, field_config, function_args): """Add extra fields to the frontend node""" - if function_args is None: + if function_args is None or function_args == "": return + # sort function_args which is a list of dicts function_args.sort(key=lambda x: x["name"]) @@ -353,7 +360,9 @@ def build_invalid_menu(invalid_components): invalid_menu[menu_name][component_name] = component_template except Exception as exc: - logger.error(f"Error while creating custom component: {exc}") + logger.error( + f"Error while creating custom component [{component_name}]: {str(exc)}" + ) return invalid_menu