From cf6ff4b493cb35079c149d304f655c2b7b6ba483 Mon Sep 17 00:00:00 2001 From: VXNCXNX Date: Sat, 15 Aug 2026 18:34:29 +0000 Subject: [PATCH] fix: replace raise StopIteration with return in watch_query Under PEP 479, raise StopIteration in generators becomes RuntimeError. --- CHANGELOG.md | 1 + litecli/packages/special/iocommands.py | 8 ++++---- tests/test_special_iocommands.py | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d91317..4507882 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Bug Fixes - Expand `~` in configured log file paths before opening the log. +- Print the usage message instead of raising `RuntimeError` when `watch` is run without a query. ### Internal diff --git a/litecli/packages/special/iocommands.py b/litecli/packages/special/iocommands.py index 434a96f..71b1151 100644 --- a/litecli/packages/special/iocommands.py +++ b/litecli/packages/special/iocommands.py @@ -467,7 +467,7 @@ def watch_query(arg: str, **kwargs: Any) -> Generator[tuple, None, None]: """ if not arg: yield (None, None, None, usage) - raise StopIteration + return seconds: float = 5.0 clear_screen = False statement = None @@ -476,7 +476,7 @@ def watch_query(arg: str, **kwargs: Any) -> Generator[tuple, None, None]: if not arg: # Oops, we parsed all the arguments without finding a statement yield (None, None, None, usage) - raise StopIteration + return (current_arg, _, arg) = arg.partition(" ") try: seconds = float(current_arg) @@ -490,7 +490,7 @@ def watch_query(arg: str, **kwargs: Any) -> Generator[tuple, None, None]: destructive_prompt = confirm_destructive_query(statement) if destructive_prompt is False: click.secho("Wise choice!") - raise StopIteration + return elif destructive_prompt is True: click.secho("Your call!") cur = kwargs["cur"] @@ -515,6 +515,6 @@ def watch_query(arg: str, **kwargs: Any) -> Generator[tuple, None, None]: # This prints the Ctrl-C character in its own line, which prevents # to print a line with the cursor positioned behind the prompt click.secho("", nl=True) - raise StopIteration + return finally: set_pager_enabled(old_pager_enabled) diff --git a/tests/test_special_iocommands.py b/tests/test_special_iocommands.py index e661b48..d5c083d 100644 --- a/tests/test_special_iocommands.py +++ b/tests/test_special_iocommands.py @@ -87,3 +87,10 @@ def test_parse_special_command_edge_cases(): sql = r"\llm+- Question" # '+' in command sets verbosity; strip('+-') removes both suffixes assert parse_special_command(sql) == ("\\llm", Verbosity.VERBOSE, "Question") + + +@pytest.mark.parametrize("command", ["watch", "watch -c", "watch 3"]) +def test_watch_without_a_query_prints_usage(command): + results = list(litecli.packages.special.execute(None, command)) + assert len(results) == 1 + assert results[0][3].startswith("Syntax: watch")