Improve `load_accounts()` logging and defaults

Move `'paper'` default entry into the initial `bidict` instead of
appending post-loop. Add per-provider branch logging: an `info`-level
msg accumulating each loaded `account_alias` and a `debug`-level msg
(using `ppfmt()`) when a provider is skipped bc it wasn't requested.

Also,
- Early-`continue` when `accounts_section is None` instead of nesting
  inside an `else`.
- Import `ppfmt` from `tractor.devx.pformat`.
- Tighten union-type annotations to `X|Y` style.
- De-structure loop vars for readability.

(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
fix_kraken_account_alias_mismatch_reporting
Gud Boi 2026-03-31 14:16:40 -04:00
parent ebc5bbd42b
commit 923b4de296
1 changed files with 45 additions and 18 deletions

View File

@ -37,6 +37,7 @@ except ModuleNotFoundError:
from tractor._exceptions import reg_err_types
from tractor.devx.pformat import ppfmt
from .log import get_logger
log = get_logger('broker-config')
@ -358,29 +359,55 @@ def write(
def load_accounts(
providers: list[str]|None = None
) -> bidict[str, str|None]:
conf, path = load(
conf_name='brokers',
)
accounts = bidict()
for provider_name, section in conf.items():
accounts_section = section.get('accounts')
if (
providers is None or
providers and provider_name in providers
):
accounts = bidict({
# XXX, default paper-engine entry; this MUST be set.
'paper': None,
})
msg: str = (
'Loading account(s) from `brokers.toml`,\n'
)
for (
provider_name,
section,
) in conf.items():
accounts_section: dict[str, str] = section.get('accounts')
if accounts_section is None:
log.warning(f'No accounts named for {provider_name}?')
msg += f'No accounts declared for {provider_name!r}?\n'
continue
# msg += f'Loaded accounts for {provider_name!r}?\n'
if (
providers is None
or (
providers
and
provider_name in providers
)
):
for (
label,
value,
) in accounts_section.items():
account_alias: str = f'{provider_name}.{label}'
accounts[account_alias] = value
msg += f'{account_alias} = {value!r}\n'
else:
for label, value in accounts_section.items():
accounts[
f'{provider_name}.{label}'
] = value
# our default paper engine entry
accounts['paper'] = None
log.debug(
f'NOT loading account(s) for entry in `brokers.toml`,\n'
f'The account provider was not requested for loading.\n'
f'requested-providers: {providers!r}\n'
f'this-provider: {provider_name!r}\n'
f'\n'
f'{ppfmt(accounts_section)}\n'
)
# ?TODO? mk this bp work?
# breakpoint()
log.info(msg)
return accounts