fix(capture): map asyncssh.KeyImportError to SCREENSHOT_UNAVAILABLE
Core Architecture & Invariant CI / validate (push) Successful in 16s
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:
1 parent
85a5acad35
commit
aac00356a1
2 files changed
+20
-2
No files matched your search
@@ -105,7 +105,7 @@ class AsyncSshCaptureTransport:
|
||||
async with sftp.open(remote_path, "rb") as handle:
|
||||
data = await handle.read()
|
||||
return bytes(data)
|
||||
except asyncssh.Error, OSError:
|
||||
except asyncssh.Error, asyncssh.KeyImportError, OSError:
|
||||
await self._close_handles()
|
||||
raise
|
||||
finally:
|
||||
@@ -192,7 +192,7 @@ class CaptureClient:
|
||||
)
|
||||
except TvError:
|
||||
raise
|
||||
except (asyncssh.Error, OSError) as exc:
|
||||
except (asyncssh.Error, asyncssh.KeyImportError, OSError) as exc:
|
||||
raise TvError(
|
||||
ErrorCode.SCREENSHOT_UNAVAILABLE,
|
||||
f"Failed to retrieve screenshot over SSH/SFTP: {exc}",
|
||||
|
||||
@@ -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 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
|
||||
Reference in new issue
Block a user