diff --git a/packages/framework/src/Framework/Exceptions/InvalidConfigurationException.php b/packages/framework/src/Framework/Exceptions/InvalidConfigurationException.php index 67a13ba331c..694566ed717 100644 --- a/packages/framework/src/Framework/Exceptions/InvalidConfigurationException.php +++ b/packages/framework/src/Framework/Exceptions/InvalidConfigurationException.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Exceptions; +use Throwable; use Hyde\Facades\Filesystem; use InvalidArgumentException; @@ -13,13 +14,13 @@ class InvalidConfigurationException extends InvalidArgumentException { - public function __construct(string $message = 'Invalid configuration detected.', ?string $namespace = null, ?string $key = null) + public function __construct(string $message = 'Invalid configuration detected.', ?string $namespace = null, ?string $key = null, ?Throwable $previous = null) { if ($namespace && $key) { [$this->file, $this->line] = $this->findConfigLine($namespace, $key); } - parent::__construct($message); + parent::__construct($message, previous: $previous); } /** diff --git a/packages/framework/tests/Unit/CustomExceptionsTest.php b/packages/framework/tests/Unit/CustomExceptionsTest.php index dc6e9b460f7..6009a31bc4e 100644 --- a/packages/framework/tests/Unit/CustomExceptionsTest.php +++ b/packages/framework/tests/Unit/CustomExceptionsTest.php @@ -201,4 +201,13 @@ public function testInvalidConfigurationExceptionWithNamespaceAndKey() $this->assertStringContainsString('config'.DIRECTORY_SEPARATOR.'hyde.php', $exception->getFile()); $this->assertGreaterThan(0, $exception->getLine()); } + + public function testInvalidConfigurationExceptionWithPreviousThrowable() + { + $previous = new Exception('Previous exception.'); + $exception = new InvalidConfigurationException('Invalid configuration.', 'hyde', 'name', $previous); + + $this->assertSame('Invalid configuration.', $exception->getMessage()); + $this->assertSame($previous, $exception->getPrevious()); + } }