From d6f3f47df399b314dff4d02534c4ff7628f66475 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 2 Oct 2025 12:17:57 -0400 Subject: [PATCH] accounting.calc: `.error()` on bad txn-time fields.. Since i'm seeing IB records with a `None` value and i don't want to be debugging every time order-mode boots up.. Also use `pdb=debug_mode` in `.open_ledger_dfs()` --- piker/accounting/calc.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/piker/accounting/calc.py b/piker/accounting/calc.py index c60ed3dd..4079b747 100644 --- a/piker/accounting/calc.py +++ b/piker/accounting/calc.py @@ -289,15 +289,26 @@ def iter_by_dt( else: continue - # XXX: should never get here.. + # XXX: we should never really get here bc it means some kinda + # bad txn-record (field) data.. + # + # -> set the `debug_mode = True` if you want to trace such + # cases from REPL ;) else: - with maybe_open_crash_handler(pdb=True): - raise ValueError( - f'Invalid txn time ??\n' - f'txn-id: {k!r}\n' - f'{k!r}: {v!r}\n' - ) - # assert v is not None, f'No valid value for `{k}`!?' + debug_mode: bool = False + report: str = ( + f'Invalid txn time ??\n' + f'txn-id: {k!r}\n' + f'{k!r}: {v!r}\n' + ) + if debug_mode: + with maybe_open_crash_handler( + pdb=debug_mode, + raise_on_exit=False, + ): + raise ValueError(report) + else: + log.error(report) if _invalid is not None: _invalid.append(tx) @@ -400,7 +411,10 @@ def open_ledger_dfs( can update the ledger on exit. ''' - with maybe_open_crash_handler(pdb=debug_mode): + with maybe_open_crash_handler( + pdb=debug_mode, + # raise_on_exit=False, + ): if not ledger: import time from ._ledger import open_trade_ledger