-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[12.x] Standardize error handling patterns across components #57745
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
Conversation
- Create HandlesExceptions trait for consistent error reporting - Add standardized exception context building - Implement consistent logging levels based on exception types - Update SyncQueue to use standardized error handling with job context - Update Database Connection to use standardized query exception reporting Key improvements: - Consistent exception reporting across all components - Rich context information for better debugging - Fallback mechanisms when exception handlers fail - Configurable logging levels per exception type - Better separation of concerns for error handling Benefits: - Improved debugging with consistent context - Better error tracking and monitoring - Reduced code duplication in error handling - More maintainable exception management - Enhanced observability across the framework All changes maintain backward compatibility while providing a foundation for consistent error handling patterns.
| * | ||
| * @param \Throwable $exception | ||
| * @param mixed $default | ||
| * @param array $context |
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.
Not sure if you want to narrow this down:
| * @param array $context | |
| * @param array<string, mixed> $context |
or perhaps, if you want it to be flat
| * @param array $context | |
| * @param array<string, scalar> $context |
| $levelMap = [ | ||
| 'InvalidArgumentException' => 'warning', | ||
| 'LogicException' => 'error', | ||
| 'RuntimeException' => 'error', | ||
| 'BadMethodCallException' => 'error', | ||
| 'OutOfBoundsException' => 'warning', | ||
| 'UnexpectedValueException' => 'warning', | ||
| ]; |
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.
Wouldn't $levelMap be a good candidate for a class property?
| 'InvalidArgumentException' => 'warning', | ||
| 'LogicException' => 'error', | ||
| 'RuntimeException' => 'error', | ||
| 'BadMethodCallException' => 'error', | ||
| 'OutOfBoundsException' => 'warning', | ||
| 'UnexpectedValueException' => 'warning', |
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.
Wouldn't it be state of the art to make the level an enum?
Summary
This PR introduces consistent error handling patterns across Laravel components through a new standardized trait and updates to key framework classes.
Changes Made
New Error Handling Foundation
Updated Components
Queue System (SyncQueue)
Database Layer (Connection)
Key Features
Consistent Error Reporting
Enhanced Debugging
Flexible Configuration
Robust Fallback Mechanisms
Benefits
Backward Compatibility
All changes are fully backward compatible:
Testing
This enhancement establishes a foundation for consistent error handling patterns throughout the Laravel framework while maintaining full backward compatibility.