diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 054f9f2a98e..c1ee17ed5da 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -12,6 +12,7 @@ This serves two purposes: ### Added - Added support for setting custom content when calling source file creator actions directly in https://github.com/hydephp/develop/pull/1393 - Added support for setting a custom post date when calling post file creator action directly in https://github.com/hydephp/develop/pull/1393 +- Added optional `FileNotFoundException` constructor parameter to set a custom exception message https://github.com/hydephp/develop/pull/1398 - The realtime compiler dashboard is now interactive, and allows you to make edits to your project right from the browser https://github.com/hydephp/develop/pull/1392 ### Changed diff --git a/packages/framework/src/Framework/Exceptions/FileNotFoundException.php b/packages/framework/src/Framework/Exceptions/FileNotFoundException.php index 8bd6298c279..417a18e3ea7 100644 --- a/packages/framework/src/Framework/Exceptions/FileNotFoundException.php +++ b/packages/framework/src/Framework/Exceptions/FileNotFoundException.php @@ -17,8 +17,8 @@ class FileNotFoundException extends Exception /** @var int */ protected $code = 404; - public function __construct(?string $path = null) + public function __construct(?string $path = null, ?string $customMessage = null) { - parent::__construct($path ? sprintf('File [%s] not found.', Hyde::pathToRelative($path)) : $this->message); + parent::__construct($customMessage ?? ($path ? sprintf('File [%s] not found.', Hyde::pathToRelative($path)) : $this->message)); } } diff --git a/packages/framework/tests/Unit/CustomExceptionsTest.php b/packages/framework/tests/Unit/CustomExceptionsTest.php index 30c7eec44cf..5103307be25 100644 --- a/packages/framework/tests/Unit/CustomExceptionsTest.php +++ b/packages/framework/tests/Unit/CustomExceptionsTest.php @@ -56,6 +56,11 @@ public function testFileNotFoundExceptionWithAbsolutePath() $this->assertSame('File [foo] not found.', (new FileNotFoundException(Hyde::path('foo')))->getMessage()); } + public function testFileNotFoundExceptionWithCustomPath() + { + $this->assertSame('foo', (new FileNotFoundException(customMessage: 'foo'))->getMessage()); + } + public function testRouteNotFoundExceptionWithDefaultMessage() { $this->assertSame('Route not found.', (new RouteNotFoundException())->getMessage());