Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Filename matcher error handling#157

Open
angiebecerra020 wants to merge 6 commits into
facebookincubator:mainfrom
angiebecerra020:filename_matcher_errorHandling
Open

Filename matcher error handling#157
angiebecerra020 wants to merge 6 commits into
facebookincubator:mainfrom
angiebecerra020:filename_matcher_errorHandling

Conversation

@angiebecerra020

Copy link
Copy Markdown

This PR improves the error handling mechanism for filename matching and enhances the overall stability of the tool by preventing unhandled crashes.

Changes Introduced:
✅ Added a custom exception FilenameMatcherError to handle errors when calling filename_matcher.
✅ Wrapped key functions (do, run, test) in try-except blocks to catch and log errors gracefully.
✅ Improved logging for better debugging and visibility of issues.
✅ Introduced a new test_filename_matcher command to verify filename matching logic.
✅ Updated test command to properly handle errors and exit with an appropriate failure status.

Why This Change?
Previously, unhandled exceptions in filename_matcher could cause crashes, making debugging difficult. This update improves robustness by ensuring errors are logged and handled properly.

How to Test?
Run python main.py test some_codemod.py and verify that filename matching errors are properly caught and displayed.
Try using invalid inputs for filename matching to see how errors are handled.
Run python main.py test_filename_matcher to validate the new testing command.
Impact & Risk Assessment:
🚀 Improves Stability: Prevents silent crashes and enhances debugging experience.
📢 Better Logging: Users get clearer feedback on errors.
✅ Backwards Compatible: No breaking changes introduced.

Would love feedback on any additional edge cases to test! 🙌

This commit adds error handling to the filename_matcher call within the refactor_dir method. In case of an exception while processing a file, the error is caught and logged instead of causing the process to fail. This ensures better robustness and visibility into issues that may occur during the file processing workflow.
This commit introduces retry logic to improve error handling when calling the filename_matcher function. If an error occurs, the process will attempt to call the function up to 3 times before giving up. A delay of 1 second between each retry helps mitigate transient issues. This change ensures that errors are handled more gracefully and reduces the likelihood of failing due to temporary issues with file processing.
This commit introduces unit tests to validate the improvements made to the error handling of the filename_matcher function. The tests include:
- Simulating permission errors and verifying retry behavior.
- Testing custom error handling for file not found errors.
- Ensuring retries are triggered for other generic exceptions.
These tests ensure that the new error-handling logic is working as expected.
This commit introduces unit tests to validate the improvements made to the error handling of the filename_matcher function. The tests include:
- Simulating permission errors and verifying retry behavior.
- Testing custom error handling for file not found errors.
- Ensuring retries are triggered for other generic exceptions.
These tests ensure that the new error-handling logic is working as expected.
mproved error handling when calling filename_matcher by adding a FilenameMatcherError exception.
Wrapped key command functions (do, run, test) with try-except blocks to prevent unhandled crashes.
Enhanced logging to provide better debugging information in case of errors.
Introduced a new command test_filename_matcher to manually verify filename matching logic.
Updated test command to properly handle filename matching errors and exit with failure status if needed.
Ensured all error messages are logged and displayed clearly to the user.
@facebook-github-bot

Copy link
Copy Markdown

Hi @angiebecerra020!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Comment thread bowler/tool.py
max_retries = 3
retries = 0

while retries < max_retries:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something seems wrong with the indentation on this block, it displays at the left margin for me.

Comment thread bowler/query.py
import logging
import pathlib
import re
import time # added by Angie Becerra

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think you need this line at all?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants