Propagate error types when awaiting on durable coroutines
Closed this issue · 1 comments
achille-roussel commented
Take this code snippet as example to reproduce the issue:
from fastapi import FastAPI
from dispatch.fastapi import Dispatch
import requests
app = FastAPI()
dispatch = Dispatch(app)
@dispatch.coroutine()
async def get(something):
raise ValueError("This is an error")
@dispatch.coroutine()
async def publish():
return await get.call('this')
@app.get('/')
def root():
publish.dispatch()
return "OK"While the exception thrown by the call to get is propagated, it appears to be turned into a RuntimeError (originally a ValueError).
Preserving the error type is important because exception handling in Python is based on types, not values (e.g., with try/except).
This is the exception that gets raised when executing this code:
unexpected exception occurred during coroutine scheduling
Traceback (most recent call last):
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/scheduler.py", line 162, in run
return self._run(input)
^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/scheduler.py", line 251, in _run
coroutine_yield = coroutine.run()
^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/scheduler.py", line 116, in run
return self.coroutine.send(None)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/experimental/durable/function.py", line 218, in send
return self.coroutine.send(send)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/main.py", line 10, in get
raise ValueError("This is an error")
ValueError: This is an error
unexpected exception occurred during coroutine scheduling
Traceback (most recent call last):
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/scheduler.py", line 162, in run
return self._run(input)
^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/scheduler.py", line 251, in _run
coroutine_yield = coroutine.run()
^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/scheduler.py", line 120, in run
return self.coroutine.throw(error)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/experimental/durable/function.py", line 221, in throw
return self.coroutine.throw(typ, val, tb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/main.py", line 15, in publish
r1 = await get.call('this')
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/experimental/durable/function.py", line 285, in throw
return self.generator.throw(typ, val, tb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/function.py", line 92, in _call_async
return await dispatch.coroutine.call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/types.py", line 220, in throw
return self.__wrapped.throw(tp, *rest)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/experimental/durable/function.py", line 285, in throw
return self.generator.throw(typ, val, tb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/achilleroussel/go/src/github.com/stealthrocket/dispatch-sdk-python/src/dispatch/coroutine.py", line 14, in call
return (yield call)
^^^^^^^^^^
RuntimeError: This is an error