diff --git a/packages/framework/src/Framework/Exceptions/ParseException.php b/packages/framework/src/Framework/Exceptions/ParseException.php index 753cb870780..aaf4724ae0a 100644 --- a/packages/framework/src/Framework/Exceptions/ParseException.php +++ b/packages/framework/src/Framework/Exceptions/ParseException.php @@ -25,7 +25,9 @@ public function __construct(string $file = '', ?Throwable $previous = null) protected function formatMessage(string $file, ?Throwable $previous): string { - return rtrim(sprintf("Invalid %s in file: '%s' %s", $this->getTypeLabel($file), $file, $this->getContext($previous))); + $fileLabel = $file ? sprintf(": '%s'", $file) : ''; + + return rtrim(sprintf('Invalid %s in file%s %s', $this->getTypeLabel($file), $fileLabel, $this->getContext($previous))); } protected function getTypeLabel(string $file): string diff --git a/packages/framework/tests/Unit/CustomExceptionsTest.php b/packages/framework/tests/Unit/CustomExceptionsTest.php index fcaeb77b1f3..e3894eec0a0 100644 --- a/packages/framework/tests/Unit/CustomExceptionsTest.php +++ b/packages/framework/tests/Unit/CustomExceptionsTest.php @@ -121,7 +121,7 @@ public function testParseExceptionWithDefaultMessage() { $exception = new ParseException(); - $this->assertSame("Invalid data in file: ''", $exception->getMessage()); + $this->assertSame('Invalid data in file', $exception->getMessage()); } public function testParseExceptionWithFileName() @@ -158,7 +158,7 @@ public function testParseExceptionWithEmptyFileNameAndCustomMessage() $previous = new RuntimeException('Custom error message.'); $exception = new ParseException('', $previous); - $this->assertSame("Invalid data in file: '' (Custom error message)", $exception->getMessage()); + $this->assertSame('Invalid data in file (Custom error message)', $exception->getMessage()); } public function testParseExceptionWithEmptyFileNameAndEmptyPreviousMessage() @@ -166,7 +166,7 @@ public function testParseExceptionWithEmptyFileNameAndEmptyPreviousMessage() $previous = new RuntimeException(''); $exception = new ParseException('', $previous); - $this->assertSame("Invalid data in file: ''", $exception->getMessage()); + $this->assertSame('Invalid data in file', $exception->getMessage()); } public function testParseExceptionWithNoPrevious()