sweepai / sweep

Sweep: open-source AI-powered Software Developer for small features and bug fixes.
https://sweep.dev
Other
7.43k stars 425 forks source link

Sweep: Include traceback in error logs in sweepai/api.py #1761

Open sweep-nightly[bot] opened 1 year ago

sweep-nightly[bot] commented 1 year ago

In the file sweepai/api.py, the logger.error method is used to log exceptions, but it does not include traceback information. This is contrary to our coding standards, which require that all error logs use traceback during exceptions.

For example, in the terminate_thread function, the exception is logged without traceback:

except Exception as e:
    logger.error(f"Failed to terminate thread: {e}")

And in the webhook function, the exception is also logged without traceback:

except ValidationError as e:
    logger.warning(f"Failed to parse request: {e}")
    raise HTTPException(status_code=422, detail="Failed to parse request")

To fix this issue, please include traceback information in all error logs. This can be done by importing the traceback module and using traceback.format_exc() to get the traceback information, like so:

import traceback

try:
    # some code that raises an exception
except Exception as e:
    logger.error(f"Failed to terminate thread: {e}, traceback: {traceback.format_exc()}")

Please apply this change to all instances where exceptions are logged in this file.

Checklist - [X] `sweepai/api.py` βœ… Commit [`dc0f108`](https://github.com/sweepai/sweep/commit/dc0f1085ee02642ffae578b3518de0ffe9075685)
In the file sweepai/api.py, you need to modify the logger.warning and logger.error methods to include traceback information when logging exceptions. For the logger.warning method on line 715, you should change the message to include traceback information. You can do this by appending ", traceback: {traceback.format_exc()}" to the existing message. Similarly, for the logger.error method on line 775, you should also change the message to include traceback information by appending ", traceback: {traceback.format_exc()}" to the existing message. Remember to import the traceback module at the beginning of the file to use the traceback.format_exc() function.
sweep-nightly[bot] commented 1 year ago

Here's the PR! https://github.com/sweepai/sweep/pull/1763.

πŸ’Ž Sweep Pro: I'm creating this ticket using GPT-4. You have unlimited GPT-4 tickets.

Actions (click)


Step 1: πŸ”Ž Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/sweepai/sweep/blob/fe8fe122bdd8d44d869fe0b7462c59f21ab50f69/sweepai/api.py#L1-L778

Step 2: ⌨️ Coding

For the logger.warning method on line 715, you should change the message to include traceback information. You can do this by appending ", traceback: {traceback.format_exc()}" to the existing message.

Similarly, for the logger.error method on line 775, you should also change the message to include traceback information by appending ", traceback: {traceback.format_exc()}" to the existing message.

Remember to import the traceback module at the beginning of the file to use the traceback.format_exc() function.


Step 3: πŸ” Code Review

Here are my self-reviews of my changes at sweep/include-traceback-in-error-logs.

Here is the 1st review

Hi there, great job on trying to include traceback information in the error logs. However, there are a couple of changes that need to be made: - In `sweepai/api.py` on line 181, you've added traceback information to a `logger.info` method. This is not necessary as `logger.info` is used for informational messages, not error logs. Please remove the traceback information from this line. - In `sweepai/api.py` on lines 599-605, you've imported the traceback module again. This is not necessary as you've already imported it at the beginning of the file. Please remove the import statement on line 599. Keep up the good work!

I finished incorporating these changes.


πŸŽ‰ Latest improvements to Sweep:


πŸ’‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord