🐛 fix(types.py): handle exceptions when getting custom function and building field config to prevent crashes and log errors
✨ feat(types.py): add validation check for custom component before building field config to ensure only valid components are processed 🐛 fix(types.py): handle empty function_args case to prevent errors when adding extra fields to the frontend node 🐛 fix(types.py): handle exceptions when creating custom component to prevent crashes and log errors
This commit is contained in:
parent
9cd919b7f5
commit
d579257f0d
1 changed files with 15 additions and 6 deletions
|
|
@ -186,21 +186,28 @@ def update_display_name_and_description(frontend_node, template_config):
|
||||||
frontend_node["description"] = template_config["description"]
|
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"""
|
"""Build the field configuration for a custom component"""
|
||||||
|
is_valid = custom_component.is_check_valid()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
custom_class = get_function_custom(custom_component.code)
|
custom_class = get_function_custom(custom_component.code)
|
||||||
return custom_class().build_config()
|
|
||||||
|
|
||||||
except Exception as exc:
|
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 {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def add_extra_fields(frontend_node, field_config, function_args):
|
def add_extra_fields(frontend_node, field_config, function_args):
|
||||||
"""Add extra fields to the frontend node"""
|
"""Add extra fields to the frontend node"""
|
||||||
if function_args is None:
|
if function_args is None or function_args == "":
|
||||||
return
|
return
|
||||||
|
|
||||||
# sort function_args which is a list of dicts
|
# sort function_args which is a list of dicts
|
||||||
function_args.sort(key=lambda x: x["name"])
|
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
|
invalid_menu[menu_name][component_name] = component_template
|
||||||
|
|
||||||
except Exception as exc:
|
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
|
return invalid_menu
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue