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:
parent
0b15084412
commit
450b371566
2 changed files with 12 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import operator
|
import operator
|
||||||
|
import re
|
||||||
from typing import Any, ClassVar
|
from typing import Any, ClassVar
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
|
|
@ -93,7 +94,15 @@ class BaseComponent:
|
||||||
if not self._code:
|
if not self._code:
|
||||||
return {}
|
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)
|
component_instance = cc_class(_code=self._code)
|
||||||
return self.get_template_config(component_instance)
|
return self.get_template_config(component_instance)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from .data import Data
|
from .data import Data
|
||||||
from .dotdict import dotdict
|
from .dotdict import dotdict
|
||||||
|
from .message import Message
|
||||||
|
|
||||||
__all__ = ["Data", "dotdict"]
|
__all__ = ["Data", "dotdict", "Message"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue