Skip to content

Commit 7d25d9d

Browse files
committed
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.
1 parent 7e40857 commit 7d25d9d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

roborock/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ def wrapper(*args, **kwargs):
9191
context: RoborockContext = ctx.obj
9292

9393
async def run():
94-
return await func(*args, **kwargs)
94+
try:
95+
await func(*args, **kwargs)
96+
except Exception:
97+
_LOGGER.exception("Uncaught exception in command")
98+
click.echo(f"Error: {sys.exc_info()[1]}", err=True)
99+
finally:
100+
await context.cleanup()
95101

96102
if context.is_session_mode():
97103
# Session mode - run in the persistent loop

0 commit comments

Comments
 (0)