Skip to content

Commit 3736579

Browse files
Vishwa Prakash Gayasenfacebook-github-bot
authored andcommitted
Align exceptions between py3 and python
Summary: - During connection establishment if Thrift python receives a C++ exception it simply throws it. This shows up as RuntimeError in python - Thirft-py3 used to gracefully convert C++ exceptions to python exceptions using a function - Use the same function in thrift python to align exceptions. Reviewed By: ahilger Differential Revision: D75506095 fbshipit-source-id: 0da292d2d210fe14e95a7bc7c006f1b35b4050ce
1 parent ae772ea commit 3736579

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

thrift/lib/py3/test/auto_migrate/clients.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ async def test_none_arguments(self) -> None:
118118
easy(),
119119
)
120120

121-
@brokenInAutoMigrate()
122121
def test_bad_unix_domain_socket_raises_TransportError_on_connection(self) -> None:
123122
with tempfile.TemporaryDirectory() as tempdir, socket.socket(
124123
socket.AF_UNIX, socket.SOCK_STREAM
@@ -131,7 +130,6 @@ async def connect_to_unlistened_socket() -> None:
131130
pass
132131

133132
loop = asyncio.get_event_loop()
134-
# thrift-python raises RuntimeError from AsyncSocketException
135133
with self.assertRaises(TransportError) as cm:
136134
loop.run_until_complete(connect_to_unlistened_socket())
137135
ex = cm.exception

thrift/lib/python/client/async_client_factory.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ from cython.operator cimport dereference as deref
2626
from folly.futures cimport bridgeFutureWith
2727
from libc.stdint cimport uint32_t
2828
from libcpp.memory cimport make_shared, static_pointer_cast
29+
from thrift.python.exceptions cimport create_py_exception
2930
from libcpp.string cimport string
3031
from libcpp.utility cimport move as cmove
3132
from thrift.python.client.async_client cimport AsyncClient
@@ -253,10 +254,7 @@ cdef void requestchannel_callback(
253254
cdef AsyncClient client = <object> userData
254255
future = client._connect_future
255256
if result.hasException():
256-
try:
257-
result.exception().throw_exception()
258-
except Exception as pyex:
259-
future.set_exception(pyex)
257+
future.set_exception(create_py_exception(result.exception(), None))
260258
else:
261259
client.bind_client(cmove(result.value()))
262260
future.set_result(None)

0 commit comments

Comments
 (0)