core: minor error handling tweaks
This commit is contained in:
parent
2a2478bfa9
commit
831fee42a1
3 changed files with 13 additions and 8 deletions
|
@ -110,11 +110,13 @@ def test_sort_res_by() -> None:
|
||||||
|
|
||||||
# todo proper typevar?
|
# todo proper typevar?
|
||||||
from datetime import datetime
|
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,)
|
e.args = e.args + (dt,)
|
||||||
# todo not sure if should return new exception?
|
# 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)
|
set_error_datetime(e, dt)
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
|
|
@ -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?
|
# todo doctor: could have a suggesion to wrap dataframes with it?? discover by return type?
|
||||||
|
|
||||||
|
|
||||||
|
import traceback
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from .error import extract_error_datetime
|
from .error import extract_error_datetime
|
||||||
def error_to_row(e: Exception, *, dt_col: str='dt') -> Dict[str, Any]:
|
def error_to_row(e: Exception, *, dt_col: str='dt', tz=None) -> Dict[str, Any]:
|
||||||
# TODO attach traceback?
|
|
||||||
edt = extract_error_datetime(e)
|
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 {
|
return {
|
||||||
'error': str(e),
|
'error': estr,
|
||||||
dt_col : edt,
|
dt_col : edt,
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,11 @@ def to_note(x: Org) -> OrgNote:
|
||||||
try:
|
try:
|
||||||
# TODO(porg) not sure if created should ever throw... maybe warning/log?
|
# TODO(porg) not sure if created should ever throw... maybe warning/log?
|
||||||
c = x.created
|
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...
|
# meh. not sure if should return date...
|
||||||
created = None
|
created = None
|
||||||
else:
|
|
||||||
created = c
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
created = None
|
created = None
|
||||||
return OrgNote(
|
return OrgNote(
|
||||||
|
|
Loading…
Add table
Reference in a new issue