diff --git a/my/core/__init__.py b/my/core/__init__.py index e86eb81..34a3e0a 100644 --- a/my/core/__init__.py +++ b/my/core/__init__.py @@ -7,3 +7,5 @@ from .common import stat, Stats from .cfg import make_config from .util import __NOT_HPI_MODULE__ + +from .error import Res, unwrap diff --git a/my/core/error.py b/my/core/error.py index 19f479c..338b651 100644 --- a/my/core/error.py +++ b/my/core/error.py @@ -108,6 +108,9 @@ def set_error_datetime(e: Exception, dt: datetime) -> None: e.args = e.args + (dt,) # todo not sure if should return new exception? +def attach_dt(e: Exception, *, dt: datetime) -> Exception: + set_error_datetime(e, dt) + return e # todo it might be problematic because might mess with timezones (when it's converted to string, it's converted to a shift) def extract_error_datetime(e: Exception) -> Optional[datetime]: diff --git a/my/core/pandas.py b/my/core/pandas.py index 8cf8e58..9a0fda2 100644 --- a/my/core/pandas.py +++ b/my/core/pandas.py @@ -51,3 +51,14 @@ def check_dataframe(f: FuncT) -> FuncT: return wrapper # type: ignore[return-value] # todo doctor: could have a suggesion to wrap dataframes with it?? discover by return type? + + +from typing import Dict, Any +from .error import extract_error_datetime +def error_to_row(e: Exception, *, dt_col: str='dt') -> Dict[str, Any]: + # TODO attach traceback? + edt = extract_error_datetime(e) + return { + 'error': str(e), + dt_col : edt, + }