spiral/exceptions
Universal exception handling component for PHP/Spiral. Provides a consistent way to catch, format, report, and render exceptions across applications and frameworks, with strong static analysis support, tests, and clean integration in Spiral projects.
composer require spiral/exceptionsDomainException, ValidationException, RuntimeException) to replace generic Exception in your domain layer.spiral/exceptions’ InfrastructureException to preserve context:
try {
$result = $this->db->fetch($sql);
} catch (\PDOException $e) {
throw new InfrastructureException('Failed to fetch user', 0, $e);
}
src/Exceptions directory in the repo (if available) for class hierarchy and interface contracts like ExceptionInterface.
renderDebugState() method for debugging purposes (v1.2.2+).DomainException to model business rule failures (e.g., UserAlreadyExistsException extends DomainException).ValidationException with structured data:
throw new ValidationException([
'email' => 'Already in use',
'password' => 'Too short'
]);
throw new InfrastructureException('Payment failed', 0, $gatewayException);
ValidationException in controllers for 422 responses, and InfrastructureException for 5xx logs.ErrorHandler.renderDebugState() in development environments to output detailed exception context (e.g., validation errors, nested exceptions):
if (app()->environment('local')) {
echo (new ValidationException(['field' => 'Invalid']))->renderDebugState();
}
getErrorCode()) but keep them thin—avoid business logic in exceptions.getPrevious() to traverse the exception chain. Log the last exception in the chain for root-cause visibility.
renderDebugState() for quick debugging in local/dev environments (avoid in production).instanceof sprawl).spiral/log or PSR-3 logger for rich diagnostics.renderDebugState() may expose sensitive data—sanitize output for production-like environments or restrict usage to local/dev environments.How can I help you explore Laravel packages today?