fix: raise ImportError instead of silencing AttributeError (#4812)

* fix: raise ImportError instead of silencing AttributeError

* chore: add Message class to init for import standardization

* feat: add exception message pattern check for import errors

* refactor: simplify code
This commit is contained in:
Ítalo Johnny 2024-11-25 11:14:57 -03:00 committed by GitHub
commit 450b371566
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import operator
import re
from typing import Any, ClassVar
from uuid import UUID
@ -93,7 +94,15 @@ class BaseComponent:
if not self._code:
return {}
cc_class = eval_custom_component_code(self._code)
try:
cc_class = eval_custom_component_code(self._code)
except AttributeError as e:
pattern = r"module '.*?' has no attribute '.*?'"
if re.search(pattern, str(e)):
raise ImportError(e) from e
raise
component_instance = cc_class(_code=self._code)
return self.get_template_config(component_instance)

View file

@ -1,4 +1,5 @@
from .data import Data
from .dotdict import dotdict
from .message import Message
__all__ = ["Data", "dotdict"]
__all__ = ["Data", "dotdict", "Message"]