Open sweep-nightly[bot] opened 1 year ago
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
sweepai/utils/search_and_replace.py
β
Commit 2f08043
The changes are constrained to the file_path and code mentioned in file_path. These are clear and detailed natural language descriptions of modifications to be made in file_path. The relevant_snippets_in_repo are read-only.
In the file sweepai/utils/search_and_replace.py, the get_files_to_change
function needs to be modified to include traceback in the log messages. This can be done by importing the traceback module at the beginning of the file and then using traceback.format_exc()
to get the stack trace. The stack trace should then be included in the log message.
The relevant snippet from file_path in the format file_path:start_idx-end_idx is sweepai/utils/search_and_replace.py:610-615. This is the part of the code where the exception is caught and logged without traceback.
The code should be modified as follows:
import traceback
# ...
except RegexMatchError as e:
logger.warning(f"Failed to parse! Retrying...\n{traceback.format_exc()}")
self.delete_messages_from_chat("files_to_change")
self.delete_messages_from_chat("pr_diffs")
```</blockquote>
- [X] `sweepai/core/sweep_bot.py` β
Commit [`455d4c0`](https://github.com/sweepai/sweep/commit/455d4c0e4e1f8339fecfd4a5ef1f1cbd4bf45d55)
<blockquote>The changes are constrained to the file_path and code mentioned in sweepai/core/sweep_bot.py.
In the function `generate_subissues`, the exception handling code needs to be modified to include traceback. The relevant snippet is sweepai/core/sweep_bot.py:213-216. The code should be changed to:
```python
except RegexMatchError:
logger.warning(f"Failed to parse! Retrying...\n{traceback.format_exc()}")
self.delete_messages_from_chat("files_to_change")
Similarly, in the function get_files_to_change
, the exception handling code needs to be modified to include traceback. The relevant snippet is sweepai/core/sweep_bot.py:392-395. The code should be changed to:
except RegexMatchError:
logger.warning(f"Failed to parse! Retrying...\n{traceback.format_exc()}")
self.delete_messages_from_chat("files_to_change")
self.delete_messages_from_chat("pr_diffs")
In both cases, the traceback
module needs to be imported at the beginning of the file.
sweepai/core/lexical_search.py
β
Commit f407ea5
The changes are constrained to the file_path and code mentioned in file_path. These are clear and detailed natural language descriptions of modifications to be made in file_path. The relevant_snippets_in_repo are read-only.
In the file sweepai/core/lexical_search.py, there are two places where exceptions are caught and logged without traceback. These are in the functions prepare_index_from_docs and search_index.
In the prepare_index_from_docs function, the relevant code is:
try:
writer.commit()
except SystemExit:
raise SystemExit
except Exception as e:
logger.error(e)
This should be changed to:
import traceback
try:
writer.commit()
except SystemExit:
raise SystemExit
except Exception:
logger.error(f"Error occurred:\n{traceback.format_exc()}")
In the search_index function, the relevant code is:
except SystemExit:
raise SystemExit
except Exception as e:
logger.print(e)
traceback.print_exc()
This should be changed to:
import traceback
except SystemExit:
raise SystemExit
except Exception:
logger.print(f"Error occurred:\n{traceback.format_exc()}")
```</blockquote>
---
## Step 3: π Code Review
I have finished reviewing the code for completeness. I did not find errors for [`sweep/add-traceback-to-error-logs_10`](https://github.com/sweepai/sweep/commits/sweep/add-traceback-to-error-logs_10).
.
---
π Latest improvements to Sweep:
* Getting Sweep to run linters before committing! Check out [Sweep Sandbox Configs](https://docs.sweep.dev/usage/config) to set it up.
* Added support for self-hosting! Check out [Self-hosting Sweep](https://docs.sweep.dev/deployment) to get started.
* [Self Hosting] Multiple options to compute vector embeddings, configure your .env file using [VECTOR_EMBEDDING_SOURCE](https://github.com/sweepai/sweep/blob/main/sweepai/config/server.py#L144)
---
π‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.
<sup>[Join Our Discord](https://discord.com/invite/sweep)
In the file sweepai/utils/search_and_replace.py, the logger is used to log exceptions, but traceback is not used. This makes it harder to debug the code because the stack trace is not available in the logs.
For example, in the
get_files_to_change
function, exceptions are caught and logged without traceback:To fix this issue, import the traceback module and use
traceback.format_exc()
to get the stack trace. Then, include the stack trace in the log message:Please apply this change to all places in the code where exceptions are logged.
Checklist
- [X] `sweepai/utils/search_and_replace.py` β Commit [`2f08043`](https://github.com/sweepai/sweep/commit/2f08043a0697bdad7fed2f8c6aab260f132335c3) - [X] `sweepai/core/sweep_bot.py` β Commit [`455d4c0`](https://github.com/sweepai/sweep/commit/455d4c0e4e1f8339fecfd4a5ef1f1cbd4bf45d55) - [X] `sweepai/core/lexical_search.py` β Commit [`f407ea5`](https://github.com/sweepai/sweep/commit/f407ea57b107f297b9e690cb0ba394b6d1943174)