diff --git a/my/core/error.py b/my/core/error.py index e0055ab..9f20af4 100644 --- a/my/core/error.py +++ b/my/core/error.py @@ -110,11 +110,13 @@ def test_sort_res_by() -> None: # todo proper typevar? from datetime import datetime -def set_error_datetime(e: Exception, dt: datetime) -> None: +def set_error_datetime(e: Exception, dt: Optional[datetime]) -> None: + if dt is None: + return e.args = e.args + (dt,) # todo not sure if should return new exception? -def attach_dt(e: Exception, *, dt: datetime) -> Exception: +def attach_dt(e: Exception, *, dt: Optional[datetime]) -> Exception: set_error_datetime(e, dt) return e diff --git a/my/core/pandas.py b/my/core/pandas.py index 9a0fda2..9a87c89 100644 --- a/my/core/pandas.py +++ b/my/core/pandas.py @@ -53,12 +53,15 @@ def check_dataframe(f: FuncT) -> FuncT: # todo doctor: could have a suggesion to wrap dataframes with it?? discover by return type? +import traceback 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? +def error_to_row(e: Exception, *, dt_col: str='dt', tz=None) -> Dict[str, Any]: edt = extract_error_datetime(e) + if edt is not None and edt.tzinfo is None and tz is not None: + edt = edt.replace(tzinfo=tz) + estr = ''.join(traceback.format_exception(Exception, e, e.__traceback__)) return { - 'error': str(e), + 'error': estr, dt_col : edt, } diff --git a/my/orgmode.py b/my/orgmode.py index a59dce3..f9ed265 100644 --- a/my/orgmode.py +++ b/my/orgmode.py @@ -34,11 +34,11 @@ def to_note(x: Org) -> OrgNote: try: # TODO(porg) not sure if created should ever throw... maybe warning/log? c = x.created - if c is not None and isinstance(c, date): + if isinstance(c, datetime): + created = c + else: # meh. not sure if should return date... created = None - else: - created = c except Exception as e: created = None return OrgNote(