[v1.x] fix: handle non-UTF-8 bytes in stdio server stdin (#2303)
This commit is contained in:
parent
f8d98b63a7
commit
2e9897e2b9
1 changed files with 35 additions and 2 deletions
|
|
@ -44,7 +44,7 @@ async def stdio_server(
|
|||
# python is platform-dependent (Windows is particularly problematic), so we
|
||||
# re-wrap the underlying binary stream to ensure UTF-8.
|
||||
if not stdin:
|
||||
stdin = anyio.wrap_file(TextIOWrapper(sys.stdin.buffer, encoding="utf-8"))
|
||||
stdin = anyio.wrap_file(TextIOWrapper(sys.stdin.buffer, encoding="utf-8", errors="replace"))
|
||||
if not stdout:
|
||||
stdout = anyio.wrap_file(TextIOWrapper(sys.stdout.buffer, encoding="utf-8"))
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ async def stdio_server(
|
|||
async for line in stdin:
|
||||
try:
|
||||
message = types.JSONRPCMessage.model_validate_json(line)
|
||||
except Exception as exc: # pragma: no cover
|
||||
except Exception as exc:
|
||||
await read_stream_writer.send(exc)
|
||||
continue
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue