fix(capture): map asyncssh.KeyImportError to SCREENSHOT_UNAVAILABLE
Core Architecture & Invariant CI / validate (push) Successful in 16s

- src/lg_smtv_mcp/tv_core/capture.py: catch asyncssh.KeyImportError (which subclasses ValueError rather than asyncssh.Error) in AsyncSshCaptureTransport.read_and_remove() and CaptureClient.capture_frame() so encrypted/invalid SSH key errors surface as TvError(SCREENSHOT_UNAVAILABLE) and degrade gracefully on composite capture calls

- tests/test_capture.py: add test_capture_client_maps_key_import_error_to_screenshot_unavailable
This commit is contained in:
kiskaadee committed 2026-11-19 01:59:34 -05:00
1 parent 85a5acad35
commit aac00356a1
2 files changed
+20 -2

No files matched your search

+2 -2
View File
@@ -105,7 +105,7 @@ class AsyncSshCaptureTransport:
async with sftp.open(remote_path, "rb") as handle: async with sftp.open(remote_path, "rb") as handle:
data = await handle.read() data = await handle.read()
return bytes(data) return bytes(data)
except asyncssh.Error, OSError: except asyncssh.Error, asyncssh.KeyImportError, OSError:
await self._close_handles() await self._close_handles()
raise raise
finally: finally:
@@ -192,7 +192,7 @@ class CaptureClient:
) )
except TvError: except TvError:
raise raise
except (asyncssh.Error, OSError) as exc: except (asyncssh.Error, asyncssh.KeyImportError, OSError) as exc:
raise TvError( raise TvError(
ErrorCode.SCREENSHOT_UNAVAILABLE, ErrorCode.SCREENSHOT_UNAVAILABLE,
f"Failed to retrieve screenshot over SSH/SFTP: {exc}", f"Failed to retrieve screenshot over SSH/SFTP: {exc}",
+18
View File
@@ -504,3 +504,21 @@ async def test_capture_client_maps_sftp_timeout_and_cancels_read() -> None:
assert exc_info.value.code is ErrorCode.SCREENSHOT_UNAVAILABLE assert exc_info.value.code is ErrorCode.SCREENSHOT_UNAVAILABLE
assert transport.read_cancelled.is_set() assert transport.read_cancelled.is_set()
async def test_capture_client_maps_key_import_error_to_screenshot_unavailable() -> None:
transport = FakeCaptureTransport(
read_error=asyncssh.KeyImportError(
"Passphrase must be specified to import encrypted private keys"
)
)
client = CaptureClient(transport)
async def ssap_request(uri: str, payload: dict[str, Any]) -> dict[str, Any]:
_ = (uri, payload)
return {"returnValue": True}
with pytest.raises(TvError) as exc_info:
await client.capture_frame(ssap_request)
assert exc_info.value.code is ErrorCode.SCREENSHOT_UNAVAILABLE
assert "Passphrase must be specified" in exc_info.value.message