Adding error management
This commit is contained in:
@@ -7,6 +7,12 @@ from core.utils import UnreferencedNamesVisitor
|
||||
from utils.Datahelper import DataHelper
|
||||
|
||||
|
||||
class DataProcessorError(Exception):
|
||||
def __init__(self, component_id, error):
|
||||
self.component_id = component_id
|
||||
self.error = error
|
||||
|
||||
|
||||
class DataProcessor(ABC):
|
||||
"""Base class for all data processing components."""
|
||||
|
||||
@@ -27,7 +33,11 @@ class DataProducer(DataProcessor):
|
||||
pass
|
||||
|
||||
def process(self, data: Any) -> Generator[Any, None, None]:
|
||||
yield from self.emit(data)
|
||||
try:
|
||||
yield from self.emit(data)
|
||||
|
||||
except Exception as e:
|
||||
raise DataProcessorError(self.component_id, e)
|
||||
|
||||
|
||||
class DataFilter(DataProcessor):
|
||||
@@ -39,8 +49,12 @@ class DataFilter(DataProcessor):
|
||||
pass
|
||||
|
||||
def process(self, data: Any) -> Generator[Any, None, None]:
|
||||
if self.filter(data):
|
||||
yield data
|
||||
try:
|
||||
if self.filter(data):
|
||||
yield data
|
||||
|
||||
except Exception as e:
|
||||
raise DataProcessorError(self.component_id, e)
|
||||
|
||||
|
||||
class DataPresenter(DataProcessor):
|
||||
@@ -52,7 +66,11 @@ class DataPresenter(DataProcessor):
|
||||
pass
|
||||
|
||||
def process(self, data: Any) -> Generator[Any, None, None]:
|
||||
yield self.present(data)
|
||||
try:
|
||||
yield self.present(data)
|
||||
|
||||
except Exception as e:
|
||||
raise DataProcessorError(self.component_id, e)
|
||||
|
||||
|
||||
class TableDataProducer(DataProducer):
|
||||
|
||||
Reference in New Issue
Block a user