Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging.exception(HTTPException) does not print underlying chained exception #3167

Closed
ArthurKantor opened this issue Jul 30, 2018 · 2 comments
Labels

Comments

@ArthurKantor
Copy link

Long story short

Example of badness:

import logging
from aiohttp import web_exceptions   

def f():
  try:
        raise Exception('hi mom')
  except Exception as e:
        raise web_exceptions.HTTPBadRequest(reason='chaining an exception from hi mom')

try:    
    f() 
except Exception as e:   
    logging.exception(e) 

outputs

ERROR:root:chaining an exception from hi mom
Traceback (most recent call last):
  File "<ipython-input-4-6ec4e29d6e22>", line 11, in <module>
    f()
  File "<ipython-input-4-6ec4e29d6e22>", line 8, in f
    raise web_exceptions.HTTPBadRequest(reason='chaining an exception from hi mom')
aiohttp.web_exceptions.HTTPBadRequest: chaining an exception from hi mom

This probably has to do with HTTPException deriving from Response

Expected behaviour

It would be nice to also see the underlying exceptions...

def g():
    try:
        raise Exception('hi mom2')
    except Exception as e:
        raise ValueError('chaining a normal exception from hi mom2')
try:    
    g() 
except Exception as e:  
    logging.exception(e)

which outputs

ERROR:root:chaining a normal exception from hi mom2
Traceback (most recent call last):
  File "<ipython-input-6-2590806aa1fb>", line 3, in g
    raise Exception('hi mom2')
Exception: hi mom2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<ipython-input-6-2590806aa1fb>", line 7, in <module>
    g()
  File "<ipython-input-6-2590806aa1fb>", line 5, in g
    raise ValueError('chaining a normal exception from hi mom2')
ValueError: chaining a normal exception from hi mom2

Your environment

aiohttp 3.3.2
python 3.7

@asvetlov
Copy link
Member

Fixed by #3098
Will be available in the next release

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants