Skip to content

Commit 126ed48

Browse files
authored
Merge pull request #128 from stealthrocket/unpack-exit-result-error
mock server: show more info when a call fails
2 parents f35c6ba + 7849fb6 commit 126ed48

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/dispatch/test/service.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import dispatch.sdk.v1.function_pb2 as function_pb
1717
import dispatch.sdk.v1.poll_pb2 as poll_pb
1818
from dispatch.id import DispatchID
19-
from dispatch.proto import Status
19+
from dispatch.proto import CallResult, Error, Status
2020
from dispatch.test import EndpointClient
2121

2222
_default_retry_on_status = {
@@ -172,11 +172,27 @@ def dispatch_calls(self):
172172
if status == Status.OK:
173173
logger.info("call to function %s succeeded", request.function)
174174
else:
175-
logger.warning(
176-
"call to function %s failed (%s)",
177-
request.function,
178-
status,
179-
)
175+
exc = None
176+
if response.HasField("exit"):
177+
if response.exit.HasField("result"):
178+
result = response.exit.result
179+
if result.HasField("error"):
180+
exc = Error._from_proto(result.error).to_exception()
181+
182+
if exc is not None:
183+
logger.warning(
184+
"call to function %s failed (%s => %s: %s)",
185+
request.function,
186+
status,
187+
exc.__class__.__name__,
188+
str(exc),
189+
)
190+
else:
191+
logger.warning(
192+
"call to function %s failed (%s)",
193+
request.function,
194+
status,
195+
)
180196

181197
if status in self.retry_on_status:
182198
_next_queue.append((dispatch_id, request, CallType.RETRY))

0 commit comments

Comments
 (0)