App\Exceptions\Handler). This complements Laravel’s EAFP philosophy by adding error-level granularity (e.g., E_USER_WARNING vs. E_USER_ERROR), which Laravel’s exception system lacks natively.set()/restore() methods allow temporary overrides of Laravel’s error handler, useful for scoped scenarios (e.g., CLI tasks, legacy code) while preserving framework defaults. This avoids the pitfalls of @ suppression or monolithic set_error_handler implementations.ErrorException (Laravel-compatible) or custom throwables, the package integrates seamlessly with Laravel’s exception stack, enabling reuse of report()/render() logic in App\Exceptions\Handler.new ErrorHandler()->with(fn() => ...) requires no Laravel-specific configuration (e.g., service providers, config files). This reduces integration friction.ErrorException as $previous, ensuring Laravel’s exception stack (e.g., previous() calls in Handler) remains intact. This enables debugging and logging consistency.set() could interfere with framework features (e.g., debug pages, logging). Mitigation: Restrict set() to non-web contexts (e.g., CLI, queues) and document usage explicitly.E_NOTICE vs. E_WARNING), risking inconsistent handling if custom logic bypasses framework defaults. Mitigation: Reserve the package for non-critical errors (e.g., logging E_NOTICE) and use Laravel’s exception system for critical failures.expectException() or PHPUnit’s error handling. Mitigation: Isolate test cases and document mocking strategies (e.g., ErrorHandler::with() vs. expectException()).E_NOTICE but throw E_USER_ERROR)? If so, how will this integrate with Laravel’s exception hierarchy?expectException(), assertException())? Will custom error callbacks require unique test patterns?@expectedException) that might conflict with the package’s inline handlers?with()/withAll() be handled? Will they bubble up to Laravel’s global handler, or require additional logic?set_error_handler integration)?ErrorException and custom throwables. It avoids framework-specific dependencies (e.g., no service container, facades, or config requirements), making it agnostic to Laravel’s architecture.Log facade.ErrorException context) can feed into tools like Sentry or Laravel Debugbar.assertException()) with minimal adjustments.@ suppression or global set_error_handler calls with ErrorHandler::with() or ErrorHandler::withAll().// Before: Global suppression
$result = @someUnstableFunction();
// After: Granular handling
$handler = new ErrorHandler();
$result = $handler->with(fn() => someUnstableFunction(), fn(ErrorException $e) => logError($e));
with() to convert PHP errors into HTTP responses (e.g., 422 Unprocessable Entity for validation errors).
return $handler->with(fn() => $validator->validate(), fn(ErrorException $e) => response()->json(['error' => $e->getMessage()], 422));
withAll() to batch-process errors (e.g., log all failures after a job completes).
$handler->withAll(fn() => processBatch(), fn(array $errors) => logBatchErrors($errors));
set()/restore() sparingly and document usage.
$handler->set(); // Throws ErrorException globally
try {
// CLI logic
} finally {
$handler->restore(); // Revert to Laravel's handler
}
Handler via the previous property.Log facade for structured logging.ErrorHandler::with() vs. expectException()).E_ALL), enabling fine-grained filtering.Throwable, not just ErrorException.with()/withAll()) in 1–2 pilot components.@ suppression or global handlers).with() calls, error level filtering).set()/restore() for CLI or testing scenarios.How can I help you explore Laravel packages today?