- What is pioniro/contextable-exception used for?
- It is a small package that lets you throw exceptions carrying structured context data, such as a correlation ID, tenant, actor, or job key. The context survives to your exception handler or log sink, so you can read the values back when handling or logging a failure. It is essentially an interface plus a trait rather than a full framework component.
- Does pioniro/contextable-exception support Laravel 10 and Laravel 11?
- There is no release since April 2020, so its composer.json almost certainly constrains illuminate packages to Laravel 5.5 through 6.x. Installing it alongside Laravel 10 or 11 will likely fail dependency resolution or force an unwanted framework downgrade. Verify the actual illuminate constraints before attempting installation on a modern application.
- Does pioniro/contextable-exception work on PHP 8.2?
- Unlikely without changes. A 2020-era package is typically pinned to PHP 7.x, and it predates PHP 8 signature and JsonSerializable behavior changes. Its exception classes should be treated as untested on PHP 8.2 and newer unless you fork and validate them yourself.
- How do I install pioniro/contextable-exception?
- Run composer require pioniro/contextable-exception, implement the provided interface or apply the trait on the exception classes you care about, then read the context in App\Exceptions\Handler or a Monolog processor. Installation itself is trivial, but the realistic blocker is dependency conflicts with modern PHP and Laravel versions. Do a scratch-app install on your target matrix before committing.
- How do I read exception context in Laravel's exception handler?
- Call the context accessor, typically getContext(), inside Handler::report() or Handler::render(), and merge the returned array into your structured log record. Alternatively, add a Monolog processor that checks for the contextable interface and injects the context into every log entry. On Laravel 9 and later, Handler::context() can do the same job for natively contextualized exceptions.
- Is pioniro/contextable-exception still maintained?
- No. The last release was 2020-04-01, it has a single maintainer, zero stars, and no known dependents. There is no security disclosure channel and no CI signal surfacing compatibility problems. Treat it as abandoned for planning and dependency-policy purposes.
- Does Laravel's built-in Exception::context() replace this package?
- For Laravel 9 and later, largely yes. Framework exceptions support a native context() method, and Handler::context() merges it into log records, covering the same use case without an extra dependency. The package only adds value if you are on an older Laravel version or need the contract to be framework-agnostic.
- What happens if exception context contains Eloquent models, PDO handles, or closures?
- The package attaches context as-is and does not appear to sanitize values, so non-serializable data can break JSON encoding when the record is written to a log handler. A closure or PDO handle will either throw or be silently degraded depending on your encoder. Normalize context to scalars and arrays at the call site, and wrap serialization in try/catch.
- How should I test exceptions that carry context?
- Assert against getContext() in PHPUnit or Pest, checking that the expected keys and values are present after the exception is thrown. Add a case for a rethrown or wrapped exception to confirm context is preserved rather than dropped. An architecture test, such as a Pest arch() rule or PHPStan rule, can enforce that new domain exceptions implement the context contract.
- Should I use pioniro/contextable-exception in production, or is there a better alternative?
- Do not adopt it as a runtime dependency. The code is MIT licensed, so port the interface and trait into your own namespace under app/Exceptions/Concerns or an internal errors package, keeping the upstream method names so the contract stays identical. Modernize with typed properties, promoted array $context = [], return types, and real test coverage; on Laravel 9+ consider the native context() support instead.