All packages
Options for Laravel
Exceptions
Package exceptions live in RoundlyConsulting\Options\Exceptions and extend the abstract OptionException, so one catch handles all of them:
| Exception | Thrown when |
|---|---|
InvalidOptionClassName | A key isn’t registered, or a class doesn’t implement OptionInterface — also for unknown entries in config_overrides. |
InvalidOptionGroup | A group class isn’t an OptionGroup, or group set() gets an identifier that isn’t a member. |
InvalidOptionObserver | An observer class-string has no __invoke method. |
InvalidOptionPayload | Import JSON is invalid or isn’t an array, a row is neither an array nor an OptionPayload, or a row lacks a string key. |
InvalidOwnerModel | A CLI --owner isn’t an Eloquent model, --owner-id is missing, or the --as user can’t be found. |
UnauthorizedOption | Access control denies a read or a write. |
EncryptionNotSupported | encrypted() is true but castAs() returns a cast instance instead of a string. |
OptionException | Never directly — the abstract base of every exception above. |
use RoundlyConsulting\Options\Exceptions\OptionException;
use RoundlyConsulting\Options\Exceptions\UnauthorizedOption;
try {
Options::set(MaintenanceModeOption::class, true);
} catch (UnauthorizedOption $e) {
abort(403);
} catch (OptionException $e) {
report($e); // any other options error
}From the framework
- Illuminate\Validation\ValidationException — a value fails the option’s rules().
- Illuminate\Contracts\Encryption\DecryptException — encrypted ciphertext was tampered with or the APP_KEY changed.
- RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException — a config value is invalid: options.model isn’t Option or a subclass of it, an unknown key_type, a switch that isn’t a boolean, a cache.ttl that isn’t a whole number of at least 1, or a cache.store, cache.prefix or cache.tag that isn’t a string. The message names the key.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.