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()