sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18.11k stars 1.55k forks source link

How to avoid abort when the code throw an Exception #2920

Closed Huelse closed 8 months ago

Huelse commented 9 months ago

Link to code

No response

Proposal

code:

@app.post("/evaluate", name="evaluate")
async def handler(request):
    # load from ctypes cdll
    app.ctx.lib.evaluate()

logs:

[2024-02-21 02:43:17 +0000] - (sanic.access)[INFO][192.168.65.1:59074]: POST http://localhost:8000/edcc/create  500 579
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.8.1) /opt/opencv-4.8.1/modules/imgcodecs/src/loadsave.cpp:802: error: (-215:Assertion failed) !buf.empty() in function 'imdecode_'

This will abort the worker(thread), and I can't use try-except to handle it. I want to ignore it and keep the worker going on or catch the exception and return in json, not abort it.

Thanks a lot!

Additional context

No response

Is this a breaking change?

Huelse commented 8 months ago

good-for-nothing