From 7b68444c7ac9a33909ce4317234c9adf8d7c7870 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` in `.open_ledger_dfs()` Note, this had conflicts on `piker/accounting/calc.py` when rebasing onto the refactored `brokers_refinery` history which were resolved manually! --- piker/accounting/calc.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/piker/accounting/calc.py b/piker/accounting/calc.py index e9190228..12a65c86 100644 --- a/piker/accounting/calc.py +++ b/piker/accounting/calc.py @@ -294,7 +294,11 @@ def iter_by_dt( ) 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: # XXX: we should really never get here.. # only if a ledger record has no expected sort(able) @@ -304,16 +308,21 @@ def iter_by_dt( 'No (time) sortable field for TXN:\n' f'{tx!r}\n' ) + report: str = ( + f'No supported time-field found in txn !?\n' + f'\n' + f'supported-time-fields: {parsers!r}\n' + f'\n' + f'txn: {tx!r}\n' + ) if debug: - import tractor - with tractor.devx.maybe_open_crash_handler(): - raise ValueError( - f'No supported time-field found in txn !?\n' - f'\n' - f'supported-time-fields: {parsers!r}\n' - f'\n' - f'txn: {tx!r}\n' - ) + with maybe_open_crash_handler( + pdb=debug, + raise_on_exit=False, + ): + raise ValueError(report) + else: + log.error(report) if _invalid is not None: _invalid.append(tx) @@ -412,7 +421,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