Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(cli): handle screenshot output errors

cyh536e73249055
diff --git a/tests/test_cli_screenshot_command.py b/tests/test_cli_screenshot_command.py
index baeddbf15..7f63a4d7c 100644
--- a/tests/test_cli_screenshot_command.py
+++ b/tests/test_cli_screenshot_command.py
@@ -5,7 +5,7 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from vibe import cli
-from vibe.screenshot import ScreenshotError, ScreenshotResult
+from vibe.screenshot import ScreenshotError, ScreenshotResult, capture_screenshot
def test_screenshot_parser_accepts_output_and_json() -> None:
@@ -65,3 +65,15 @@ def test_cmd_screenshot_reports_errors(capsys, monkeypatch) -> None:
assert payload["ok"] is False
assert payload["code"] == "screenshot_failed"
assert payload["error"] == "display is unavailable"
+
+
+def test_capture_screenshot_wraps_output_preparation_errors(tmp_path: Path) -> None:
+ blocked_parent = tmp_path / "not-a-directory"
+ blocked_parent.write_text("blocked", encoding="utf-8")
+
+ try:
+ capture_screenshot(blocked_parent / "screen.png")
+ except ScreenshotError as exc:
+ assert "failed to prepare screenshot output path" in str(exc)
+ else:
+ raise AssertionError("expected ScreenshotError")
diff --git a/vibe/screenshot.py b/vibe/screenshot.py
index c875a38e7..4e244f142 100644
--- a/vibe/screenshot.py
+++ b/vibe/screenshot.py
@@ -39,8 +39,11 @@ def default_screenshot_path() -> Path:
def capture_screenshot(output: str | Path | None = None) -> ScreenshotResult:
"""Capture the local desktop to a PNG file."""
- output_path = _resolve_output_path(output)
- output_path.parent.mkdir(parents=True, exist_ok=True)
+ try:
+ output_path = _resolve_output_path(output)
+ output_path.parent.mkdir(parents=True, exist_ok=True)
+ except OSError as exc:
+ raise ScreenshotError(f"failed to prepare screenshot output path: {exc}") from exc
if sys.platform == "darwin":
backend = _capture_macos(output_path)
@@ -113,8 +116,11 @@ def _capture_linux(output: Path) -> str:
_run_capture_command(command, name)
return name
except ScreenshotError:
- if output.exists():
- output.unlink()
+ try:
+ if output.exists():
+ output.unlink()
+ except OSError:
+ pass
if attempted:
raise ScreenshotError(f"installed screenshot tools failed: {', '.join(attempted)}")
@@ -135,8 +141,14 @@ def _run_capture_command(command: list[str], label: str) -> None:
def _verify_output(output: Path) -> None:
- if not output.is_file():
- raise ScreenshotError(f"screenshot file was not created: {output}")
- if output.stat().st_size <= 0:
+ try:
+ if not output.is_file():
+ raise ScreenshotError(f"screenshot file was not created: {output}")
+ if output.stat().st_size > 0:
+ return
output.unlink(missing_ok=True)
- raise ScreenshotError("screenshot file was empty")
+ except ScreenshotError:
+ raise
+ except OSError as exc:
+ raise ScreenshotError(f"failed to inspect screenshot output: {exc}") from exc
+ raise ScreenshotError("screenshot file was empty")