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

Add traceback info to common error handler #1708

Merged
merged 1 commit into from
Jun 1, 2023

Conversation

Ruwann
Copy link
Member

@Ruwann Ruwann commented Jun 1, 2023

Still up for discussion: right now, when an internal server error occurs, the logged error is not really useful for the user.
For example, a KeyError will only print the missing key instead of the full stacktrace and error.

Adding it to the common error handler as that one is meant to catch all remaining errors, HTTPExceptions are handled by another error handler.

Another option would be to do like Flask and Starlette by adding a debug option, but that seems a lot of work while this current solution doesn't really have big downsides (?)

@Ruwann Ruwann requested a review from RobbeSneyders June 1, 2023 08:32
Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was bugging me already :)

connexion/middleware/exceptions.py Show resolved Hide resolved
@coveralls
Copy link

Coverage Status

Coverage: 94.042%. Remained the same when pulling ae41a30 on Ruwann:feature/exception-logging into 0c0c517 on spec-first:main.

@Ruwann Ruwann merged commit a34da31 into spec-first:main Jun 1, 2023
@julienschuermans
Copy link
Contributor

logger.error(exc, exc_info=exc)
This was much needed, thanks!

@Ruwann @RobbeSneyders I think it would it make sense to apply this same change to the http_exception and problem_handler functions in this file because neither connexion.middleware.exceptions.ProblemException nor starlette.exceptions.HTTPException have a decent __str__ implementation.

two other ideas - in case dumping the exc_info is overkill for each HTTPException or ProblemException:

  • logger.error(repr(exc)) would be useful.
  • OR just implement the __str__ method for those Exception subclasses

RobbeSneyders pushed a commit that referenced this pull request Jun 13, 2023
Follow-up on #1708
([comment](#1708 (comment)))

As mentioned there, there is a `__repr__` but not a `__str__`, leading
to an empty log message (for HTTPExceptions).

An example when running the dev server (previously the first line would
just be an empty line):
```
HTTPException(status_code=404, detail='Not Found')
INFO:     127.0.0.1:33538 - "GET /swaggers/ui/ HTTP/1.1" 404 Not Found
```

However, I would also be fine with just removing the logging here as
`HTTPException`s can be part of the normal flow, without indicating an
actual application error (case in point: raising a `Not Found`
exception)
@Ruwann Ruwann deleted the feature/exception-logging branch August 29, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants