sweepai / sweep

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

Sweep: Add a try except here with a clear log #1002

Open wwzeng1 opened 1 year ago

wwzeng1 commented 1 year ago

Details

File "/root/sweepai/utils/github_utils.py", line 201, in get_file_contents contents = file.decoded_content.decode("utf-8", errors='replace') ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/github/ContentFile.py", line 59, in decoded_content assert self.encoding == "base64", f"unsupported encoding: {self.encoding}" AssertionError: unsupported encoding: none

Files to change

No response

sweep-nightly[bot] commented 1 year ago

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

💎 Sweep Pro: I used GPT-4 to create this ticket. You have 18 GPT-4 tickets left.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

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/373be96758fe11a9acc3e0def5e130ae7214afe7/tests/archive/test_diff_parsing.py#L1-L426 https://github.com/sweepai/sweep/blob/373be96758fe11a9acc3e0def5e130ae7214afe7/sweepai/handlers/on_ticket.py#L243-L458 https://github.com/sweepai/sweep/blob/373be96758fe11a9acc3e0def5e130ae7214afe7/sweepai/core/sweep_bot.py#L1-L77 https://github.com/sweepai/sweep/blob/373be96758fe11a9acc3e0def5e130ae7214afe7/tests/archive/test_diff_parsing.py#L356-L541 https://github.com/sweepai/sweep/blob/373be96758fe11a9acc3e0def5e130ae7214afe7/sweepai/utils/config/client.py#L1-L86

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
sweepai/utils/github_utils.py In the get_file_contents function, add a try-except block around the file.decoded_content.decode("utf-8", errors='replace') line. In the except block, catch AssertionError. If an AssertionError is caught, log a message that includes the file's actual encoding, which can be accessed via file.encoding.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add try-except block to handle unsupported encoding in get_file_contents sweep/fix-unsupported-encoding

Description

This PR adds a try-except block to handle the AssertionError that occurs when the file's encoding is not "base64" in the get_file_contents function of github_utils.py. The decoded_content method assumes that the encoding is "base64", but in some cases, it can be different, leading to the error. The try-except block catches the AssertionError and logs a clear message that includes the actual encoding of the file.

Summary of Changes

  • Added a try-except block around the decoded_content method call in the get_file_contents function.
  • Catch the AssertionError and log a clear message that includes the actual encoding of the file.

This change ensures that the code gracefully handles unsupported encodings and provides a clear log message for debugging purposes.


Step 4: ⌨️ Coding

File Instructions Progress
sweepai/utils/github_utils.py In the get_file_contents function, add a try-except block around the file.decoded_content.decode("utf-8", errors='replace') line. In the except block, catch AssertionError. If an AssertionError is caught, log a message that includes the file's actual encoding, which can be accessed via file.encoding. I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are the my self-reviews of my changes at sweep/fix-unsupported-encoding.

Here is the 1st review

No changes required. The modifications in the get_file_contents function in the sweepai/utils/github_utils.py file are correctly implemented and there are no unimplemented sections. Good job!

I finished incorporating these changes.


To recreate the pull request, leave a comment prefixed with "sweep:" or edit the issue. Join Our Discord

kevinlu1248 commented 1 year ago

sweep: Retry