From 7d25d9df023d481fa6a8d19861540031df86f881 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sat, 27 Dec 2025 07:59:13 -0800 Subject: [PATCH 1/3] fix: Properly shutdown the context in the CLI This avoids leaving open a session after running commands and properly catches exceptions in the CLI commands. --- roborock/cli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roborock/cli.py b/roborock/cli.py index b043516d..d8841e4c 100644 --- a/roborock/cli.py +++ b/roborock/cli.py @@ -91,7 +91,13 @@ def wrapper(*args, **kwargs): context: RoborockContext = ctx.obj async def run(): - return await func(*args, **kwargs) + try: + await func(*args, **kwargs) + except Exception: + _LOGGER.exception("Uncaught exception in command") + click.echo(f"Error: {sys.exc_info()[1]}", err=True) + finally: + await context.cleanup() if context.is_session_mode(): # Session mode - run in the persistent loop From 9120d35c885ebb9505fad0d89db68211c3caa495 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sat, 27 Dec 2025 09:59:56 -0800 Subject: [PATCH 2/3] chore: improve error handling for session loop --- roborock/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roborock/cli.py b/roborock/cli.py index d8841e4c..a4dd414a 100644 --- a/roborock/cli.py +++ b/roborock/cli.py @@ -97,7 +97,8 @@ async def run(): _LOGGER.exception("Uncaught exception in command") click.echo(f"Error: {sys.exc_info()[1]}", err=True) finally: - await context.cleanup() + if not context.is_session_mode(): + await context.cleanup() if context.is_session_mode(): # Session mode - run in the persistent loop From 9ff90a4836dfd432215a3b021ed1215036b9bfdc Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sat, 27 Dec 2025 10:00:44 -0800 Subject: [PATCH 3/3] chore: Fix exception catching --- roborock/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roborock/cli.py b/roborock/cli.py index a4dd414a..60e32c1c 100644 --- a/roborock/cli.py +++ b/roborock/cli.py @@ -93,9 +93,9 @@ def wrapper(*args, **kwargs): async def run(): try: await func(*args, **kwargs) - except Exception: + except Exception as err: _LOGGER.exception("Uncaught exception in command") - click.echo(f"Error: {sys.exc_info()[1]}", err=True) + click.echo(f"Error: {err}", err=True) finally: if not context.is_session_mode(): await context.cleanup()