From 23dd3d260f405d41cada9d213d1b1d60c208923e Mon Sep 17 00:00:00 2001 From: Takeshi Yoshino <4511440+tyoshino@users.noreply.github.com> Date: Mon, 27 Apr 2026 13:14:11 +0000 Subject: [PATCH] feat(wish/python): change the way to handle error in init() from returning False to raising --- wish/python/src/wish_ext.cc | 8 ++++++-- wish/python/wish/client.py | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wish/python/src/wish_ext.cc b/wish/python/src/wish_ext.cc index f3d2a31..92cdf72 100644 --- a/wish/python/src/wish_ext.cc +++ b/wish/python/src/wish_ext.cc @@ -228,7 +228,9 @@ NB_MODULE(wish_ext, m) { .def(nb::init()) .def("init", [](TlsClientPy& self) { - return self.client.Init(); + if (!self.client.Init()) { + throw std::runtime_error("TlsClient.init() failed"); + } }) .def("set_on_open", [](TlsClientPy& self, nb::object cb) { self.on_open_cb = cb; @@ -291,7 +293,9 @@ NB_MODULE(wish_ext, m) { nb::class_(m, "PlainClient", nb::type_slots(plain_slots)) .def(nb::init()) .def("init", [](PlainClientPy& self) { - return self.client.Init(); + if (!self.client.Init()) { + throw std::runtime_error("PlainClient.init() failed"); + } }) .def("set_on_open", [](PlainClientPy& self, nb::object cb) { self.on_open_cb = cb; diff --git a/wish/python/wish/client.py b/wish/python/wish/client.py index eec980e..495bd19 100644 --- a/wish/python/wish/client.py +++ b/wish/python/wish/client.py @@ -12,8 +12,7 @@ def __init__(self, host, port, tls, ca_file="", cert_file="", key_file=""): self._client = wish_ext.TlsClient(ca_file, cert_file, key_file, host, port) else: self._client = wish_ext.PlainClient(host, port) - if not self._client.init(): - raise RuntimeError(f"Failed to initialize client for {host}:{port}") + self._client.init() # raises RuntimeError on failure self._loop = asyncio.get_running_loop() self._recv_queue = asyncio.Queue()