Weave 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
Contextable Exception

Contextable Exception Laravel Package

pioniro/contextable-exception

Contextable exceptions for Laravel and PHP: throw exceptions that carry structured context data, so you can attach the values, inputs, or state behind a failure and read them back later when handling or logging it. Lightweight and simple to adopt.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Contextable Exception
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.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource