chore: add comprehensive error handling and logging infrastructure#65
Open
1234-ad wants to merge 3 commits intoruxailab:mainfrom
Open
chore: add comprehensive error handling and logging infrastructure#651234-ad wants to merge 3 commits intoruxailab:mainfrom
1234-ad wants to merge 3 commits intoruxailab:mainfrom
Conversation
Add comprehensive custom exception hierarchy: - PRReviewError: Base exception for all PR review errors - GitHubAPIError: GitHub API failures with status code tracking - MetricsCalculationError: Metrics computation failures - AILabelingError: AI labeling service failures - ReviewerAssignmentError: Reviewer assignment failures - DiscordNotificationError: Discord notification failures - ConfigurationError: Configuration validation errors - ValidationError: Input validation errors Benefits: - Better error categorization and handling - Easier debugging with specific exception types - Improved error messages and context - Enables targeted exception handling in try-except blocks
Add comprehensive logging utilities:
- setup_logging(): Configure logging with console and file output
- Rotating file handler with configurable size and backup count
- LoggerMixin: Add logging to any class via inheritance
- LogLevel: Context manager for temporary log level changes
- Structured log format with filename and line numbers
- Configurable log levels and custom format strings
Benefits:
- Consistent logging across all modules
- Easy log file rotation to prevent disk space issues
- Better debugging with file/line information
- Flexible logging configuration
- Production-ready logging setup
Usage:
from logging_config import setup_logging, LoggerMixin
logger = setup_logging('my_module', level='DEBUG', log_file='logs/app.log')
logger.info('Application started')
Add comprehensive retry and resilience utilities:
- retry(): Decorator for sync functions with exponential backoff
- retry_async(): Decorator for async functions with exponential backoff
- CircuitBreaker: Prevent cascading failures with circuit breaker pattern
- Configurable retry attempts, delays, and backoff multipliers
- Custom exception handling and retry callbacks
- Detailed logging of retry attempts and failures
Benefits:
- Resilient API calls that handle transient failures
- Exponential backoff prevents overwhelming failing services
- Circuit breaker prevents cascading failures
- Better error handling and recovery
- Production-ready reliability patterns
Usage:
from retry_utils import retry, CircuitBreaker
@Retry(max_attempts=3, delay=1.0, backoff=2.0)
def fetch_github_data():
return github_client.get_pull_request(repo, pr_number)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive error handling infrastructure with custom exceptions, centralized logging, and retry mechanisms for resilient API calls.
Changes
pr_review/exceptions.pyCustom exception hierarchy:
PRReviewError: Base exception for all PR review errorsGitHubAPIError: GitHub API failures with status code trackingMetricsCalculationError: Metrics computation failuresAILabelingError: AI labeling service failuresReviewerAssignmentError: Reviewer assignment failuresDiscordNotificationError: Discord notification failuresConfigurationError: Configuration validation errorsValidationError: Input validation errorspr_review/logging_config.pyCentralized logging utilities:
setup_logging(): Configure logging with console and file outputLoggerMixin: Add logging to any class via inheritanceLogLevel: Context manager for temporary log level changespr_review/utils/retry_utils.pyRetry and resilience utilities:
@retry: Decorator for sync functions with exponential backoff@retry_async: Decorator for async functions with exponential backoffCircuitBreaker: Prevent cascading failures with circuit breaker patternBenefits
Usage Examples
Testing
Impact