NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

Package exceptions live in RoundlyConsulting\Options\Exceptions and extend the abstract OptionException, so one catch handles all of them. The one failure that isn’t an OptionException is a value an option’s rules() refuse — that throws Laravel’s ValidationException (see Validation), so catch it as well:

ExceptionThrown when
InvalidOptionClassNameA key isn’t registered, or a class doesn’t implement OptionInterface — also for unknown entries in config_overrides.
InvalidOptionGroupA group class isn’t an OptionGroup, or group set() gets an identifier that isn’t a member.
InvalidOptionObserverAn observer class-string has no __invoke method.
InvalidOptionPayloadImport JSON is invalid or isn’t an array, a row is neither an array nor an OptionPayload, lacks a string key or has a value that isn’t a string, number, boolean or null; a value isn’t a case of an EnumCast option’s enum; or options:set --json gets invalid JSON.
InvalidOwnerModelA CLI --owner isn’t an Eloquent model, --owner-id is missing or names no record, or the --as user can’t be found.
UnauthorizedOptionAccess control denies a read or a write.
EncryptionNotSupportedencrypted() is true but castAs() returns a cast instance instead of a string.
OptionExceptionNever directly — the abstract base of every exception above.
use Illuminate\Validation\ValidationException;
use RoundlyConsulting\Options\Exceptions\OptionException;
use RoundlyConsulting\Options\Exceptions\UnauthorizedOption;

try {
    Options::set(MaintenanceModeOption::class, true);
} catch (UnauthorizedOption $e) {
    abort(403);
} catch (ValidationException $e) {
    // the value failed the option's rules(); $e->errors()['value']
} 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 crypto

By 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.