Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Util Errorhandler Laravel Package

phrity/util-errorhandler

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Granular Error Handling in Laravel Applications: Enable context-specific error resolution (e.g., APIs returning structured HTTP errors, background jobs with retry logic) without overriding Laravel’s global exception handler. Aligns with Laravel’s modularity while addressing gaps in its built-in error handling (e.g., no native support for error-level filtering like E_USER_WARNING).
  • Roadmap for Resilient APIs and Microservices: Justify investment in a structured error-handling layer for projects where errors must be transformed into consistent responses (e.g., JSON APIs with 4xx/5xx payloads) or logged for observability. Supports initiatives like:
    • API-First Development: Convert PHP errors into HTTP responses (e.g., 422 Unprocessable Entity for validation errors).
    • Event-Driven Architectures: Handle errors in queues/workers (e.g., retry failed jobs or log details without crashing).
    • Legacy System Integration: Isolate error-prone blocks (e.g., third-party SDKs) without global @ suppression or monolithic try-catch wrappers.
  • Build vs. Buy Decision: Avoid reinventing error-handling logic (e.g., custom try-catch wrappers or decorators) by adopting a battle-tested, MIT-licensed package with PHP 8.1+ support. Reduces technical debt and accelerates development.
  • Use Cases:
    • APIs: Replace @ suppression with structured error responses (e.g., with() to throw ErrorException → Laravel’s render()).
    • Background Jobs: Use withAll() to collect all errors in a batch job before failing gracefully.
    • CLI Tools: Temporarily override global error handling (e.g., set() for scripts) without affecting web requests.
    • Testing: Simulate error conditions in unit tests (e.g., mock with() to trigger exceptions for edge cases).
    • Legacy Code: Wrap third-party integrations to catch errors and log them without crashing the app.

When to Consider This Package

  • Adopt When:

    • You need fine-grained control over error handling in Laravel beyond what the framework’s global App\Exceptions\Handler provides (e.g., error-level filtering like E_USER_WARNING).
    • Your project requires context-aware error resolution (e.g., different behaviors for APIs, CLI, or background jobs).
    • You’re building resilient systems where errors must be caught, transformed, or logged without disrupting the entire application (e.g., microservices, event-driven workflows).
    • You want to avoid @ suppression or global set_error_handler side effects (e.g., masking errors in specific code blocks).
    • Your team uses PHP 8.1+ (package requirement) and Laravel 10+ (LTS).
    • You’re piloting error-handling improvements and want to test a lightweight, modular solution before committing to custom logic.
  • Look Elsewhere If:

    • Your PHP version is < 8.1 (package requires ^8.1).
    • Your error-handling needs are fully covered by Laravel’s built-in tools (e.g., try-catch blocks or App\Exceptions\Handler suffice for your use cases).
    • You need advanced exception handling (e.g., custom middleware for all errors, real-time monitoring with Sentry, or complex exception hierarchies). Consider:
      • Laravel’s App\Exceptions\Handler for global exception logic.
      • Symfony’s ErrorHandler component for framework-agnostic solutions.
      • Monolithic try-catch wrappers if you require deep integration with Laravel’s exception stack.
    • Your team prefers framework-native solutions over third-party packages (e.g., custom decorators or middleware).
    • You require real-time error monitoring (e.g., Sentry, Bugsnag) as a primary use case (this package focuses on inline handling, not observability).

How to Pitch It (Stakeholders)

For Executives:

*"This package lets us turn PHP errors into actionable outcomes—whether that’s a clean API response, a logged alert, or a retryable job—without crashing the system. For example:

  • APIs: Errors become structured 422/500 responses with debug info (only in development), improving developer experience and reducing support tickets.
  • Background Jobs: Failed jobs trigger alerts or retries instead of failing silently, boosting reliability for critical workflows like payments or notifications.
  • Legacy Code: Isolate error-prone blocks (e.g., payment gateways or third-party integrations) without global workarounds like @ suppression, which hides critical issues. It’s a low-risk, high-reward addition:
  • MIT-licensed and actively maintained (last release: Dec 2025).
  • PHP 8.1+ compatible, aligning with our Laravel 10+ stack.
  • Used by [X] teams for similar challenges (e.g., [Company Y] in their microservices). We can pilot it in [critical workflow, e.g., API endpoints or job queues] to prove ROI before scaling. The payoff? Fewer crashes, better debugging, and more resilient systems—all with minimal code changes."*

For Engineers:

*"This package gives us two powerful ways to handle errors inline, with minimal boilerplate:

  1. with(): Stops execution and throws an ErrorException (or custom exception) immediately when an error occurs. Ideal for critical paths where you want to fail fast (e.g., validation, API requests).
  2. withAll(): Runs the entire block, then processes all errors at once. Perfect for batch operations or idempotent workflows where you want to collect errors before acting (e.g., bulk imports).

Why this beats alternatives:

  • No more @ suppression: Cleanly handle errors without hiding them globally.
  • Global or local control: Use set()/restore() to temporarily override Laravel’s error handler (e.g., for CLI tasks or APIs) without affecting the rest of the app.
  • Flexible outputs: Throw exceptions, return custom results, or log errors—your choice. For example:
    // Convert a PHP error into an HTTP response
    $handler->with(function () {
        $user = User::findOrFail($id); // Might throw ErrorException
    }, function (ErrorException $error) {
        return response()->json(['error' => $error->getMessage()], 404);
    });
    
  • Error-level filtering: Target specific error types (e.g., E_USER_WARNING but ignore E_NOTICE) using PHP’s error constants.

Tradeoffs:

  • Slightly more verbose than try-catch, but far more maintainable for complex flows.
  • Global handler overrides (set()) require careful use to avoid conflicts with Laravel’s App\Exceptions\Handler.

Let’s prototype this in [Module X] to compare it with our current approach. Key questions:

  • How does this integrate with Laravel’s exception stack (e.g., previous property for debugging)?
  • Can we use it to standardize error responses across APIs?
  • Will it reduce noise in logs by filtering non-critical errors (e.g., E_NOTICE)?"*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor