From 21f633a9005c9ae3dcda6c98dd3893dde65af3fa Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 31 May 2024 14:40:55 -0400 Subject: [PATCH] Use `Context` repr APIs for RPC outcome logs Delegate to the new `.repr_state: str` and adjust log level based on error vs. cancel vs. result. --- tractor/_rpc.py | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/tractor/_rpc.py b/tractor/_rpc.py index 8a1be7b..fa61577 100644 --- a/tractor/_rpc.py +++ b/tractor/_rpc.py @@ -739,37 +739,24 @@ async def _invoke( cid, )) + logmeth: Callable = log.runtime merr: Exception|None = ctx.maybe_error - ( - res_type_str, - res_str, - ) = ( - ('error', f'{type(merr)}',) if merr - else ( - 'result', - f'`{repr(ctx.outcome)}`', - ) - ) + descr_str: str = 'with final result `{repr(ctx.outcome)}`' message: str = ( - f'IPC context terminated with a final {res_type_str}\n\n' - f'{ctx}' + f'IPC context terminated {descr_str}\n\n' ) if merr: - from tractor import RemoteActorError - if not isinstance(merr, RemoteActorError): - fmt_merr: str = ( - f'\n{merr!r}\n' - # f'{merr.args[0]!r}\n' - ) - else: - fmt_merr = f'\n{merr!r}' - log.error( - message - + - fmt_merr + descr_str: str = ( + f'with ctx having {ctx.repr_state!r}\n' + f'{ctx.repr_outcome()}\n' ) - else: - log.runtime(message) + if isinstance(merr, ContextCancelled): + logmeth: Callable = log.runtime + else: + logmeth: Callable = log.error + message += f'\n{merr!r}\n' + + logmeth(message) async def try_ship_error_to_remote(