dispatchrun / dispatch-py

Python package to develop applications with Dispatch.
https://pypi.org/project/dispatch-py/
Apache License 2.0
56 stars 3 forks source link

Better handling of language usage errors #46

Closed achille-roussel closed 9 months ago

achille-roussel commented 9 months ago

Here is a script that motivated opening this issue:

from fastapi import FastAPI
from dispatch.fastapi import Dispatch

app = FastAPI()
dispatch = Dispatch(app)

@dispatch.function()
def publish(arg: str) -> str:
    r = requests.post('https://httpstat.us/200', data={'arg': arg})
    r.raise_for_status()
    return 'OK'

@app.get('/')
def endpoint():
    publish.dispatch('hello')
    return {'message': 'ok'}

The problem is there is no symbol named requests, because we forgot the import requests statement. That is supposed to raise a NameError. This error type is currently interpreted as retriable, which silences it and causes the operation to retry.

It is difficult for users to understand what they did wrong in this situation because we capture and handle the exceptions.

chriso commented 9 months ago

IMO errors should default to PERMANENT_ERROR, and retries should be opt-in. At the moment the default is TEMPORARY_ERROR.