Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/kb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,13 @@ def correct(
except ValueError as e:
click.echo(f"Error: {e}", err=True)
raise SystemExit(1) from None
except OSError as e:
# Batch write failed mid-apply; apply_corrections rolled the files back (#1 COW).
click.echo(
f"Error: correction failed and was rolled back — no files were changed ({e}).",
err=True,
)
raise SystemExit(1) from None
finally:
kb.close()

Expand Down
14 changes: 14 additions & 0 deletions tests/test_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ def _invoke(self, runner: CliRunner, memory_tree: Path, args: list[str]):
with patch("kb.cli._find_project_root", return_value=project_root):
return runner.invoke(cli, ["correct", *args], catch_exceptions=False)

def test_apply_rollback_shows_graceful_error(
self, cli_runner: CliRunner, memory_tree: Path, monkeypatch
):
"""A rolled-back batch (OSError from apply) surfaces a clean message, not a traceback (#1)."""
from kb.api import KnowledgeBase

def boom(self, *a, **k): # type: ignore[no-untyped-def]
raise OSError("disk full (simulated)")

monkeypatch.setattr(KnowledgeBase, "correct_term", boom)
result = self._invoke(cli_runner, memory_tree, ["Quartz Indexer", "Datalux", "--apply"])
assert result.exit_code == 1
assert "rolled back" in result.output.lower()

def test_scan_json_output(self, cli_runner: CliRunner, memory_tree: Path):
"""kbx correct TERM --json returns structured scan output."""
result = self._invoke(cli_runner, memory_tree, ["Quartz Indexer", "--json"])
Expand Down