-
Notifications
You must be signed in to change notification settings - Fork 110
Filename matcher error handling #157
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
base: main
Are you sure you want to change the base?
Filename matcher error handling #157
Conversation
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.
Hi @angiebecerra020! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
max_retries = 3 | ||
retries = 0 | ||
|
||
while retries < max_retries: |
There was a problem hiding this comment.
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.
@@ -9,6 +9,7 @@ | |||
import logging | |||
import pathlib | |||
import re | |||
import time # added by Angie Becerra |
There was a problem hiding this comment.
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?
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! 🙌