🎨 Work on import error handling
- Generic ErrorProducer class - Importer and managers are error producers - SGDB Auth friendly error - Bad source location friendly errors (data, config, cache) - Removed unused decorators
This commit is contained in:
28
src/errors/error_producer.py
Normal file
28
src/errors/error_producer.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from threading import Lock
|
||||
|
||||
|
||||
class ErrorProducer:
|
||||
"""
|
||||
A mixin for objects that produce errors.
|
||||
|
||||
Specifies the report_error and collect_errors methods in a thread-safe manner.
|
||||
"""
|
||||
|
||||
errors: list[Exception] = None
|
||||
errors_lock: Lock = None
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.errors = []
|
||||
self.errors_lock = Lock()
|
||||
|
||||
def report_error(self, error: Exception):
|
||||
"""Report an error"""
|
||||
with self.errors_lock:
|
||||
self.errors.append(error)
|
||||
|
||||
def collect_errors(self) -> list[Exception]:
|
||||
"""Collect and remove the errors produced by the object"""
|
||||
with self.errors_lock:
|
||||
errors = self.errors.copy()
|
||||
self.errors.clear()
|
||||
return errors
|
||||
Reference in New Issue
Block a user