core: minor helpers for error handling
This commit is contained in:
parent
d059e4aaf4
commit
fa5e181cf8
3 changed files with 16 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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]:
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue