hypercorn icon indicating copy to clipboard operation
hypercorn copied to clipboard

ImportError: cannot import name 'LifespanFailure' from 'hypercorn.utils'

Open adam-pawluczuk opened this issue 3 years ago • 5 comments

Hello.

After automatically upgrading to the newest version (0.12.0):

ImportError: cannot import name 'LifespanFailure' from 'hypercorn.utils'

I can see that in 0.12.0 LifespanFailure was renamed to LifespanFailureError (along with other renamings).

Is 0.12.0 considered to have breaking changes?

Thank you! Adam

adam-pawluczuk avatar Nov 09 '21 09:11 adam-pawluczuk

I didn't think LifespanFailure would be used outside of the Hypercorn code directly - I'd like to learn about your usage.

It is a renaming, I'll add it to the changelog.

pgjones avatar Nov 09 '21 10:11 pgjones

So basically what I have is this:

from hypercorn.utils import LifespanFailure

try:
    await self.app(<some params>)
except LifespanFailure:
    pass

It is being used like this in one of the middlewares.

adam-pawluczuk avatar Nov 09 '21 10:11 adam-pawluczuk

I'm not sure that these errors should leak out to the middleware - I guess this is an app that doesn't support lifespans?

pgjones avatar Nov 09 '21 18:11 pgjones

Yes, that makes sense. So it looks like it could be the fault on the application side then. Thank you!

adam-pawluczuk avatar Nov 30 '21 12:11 adam-pawluczuk

Thinking about this some more, I think the specification allows for any Exception subclass to be raised - so I don't think your middleware should rely on it being a LifespanFailureError.

pgjones avatar Dec 08 '21 21:12 pgjones