diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php index 828d894763e..270529ee306 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php @@ -624,7 +624,7 @@ private static function getAssertionParts( ); } catch (TypeParseTreeException $e) { $storage->docblock_issues[] = new InvalidDocblock( - 'Invalid @psalm-assert union type ' . $e, + 'Invalid @psalm-assert union type: ' . $e->getMessage(), new CodeLocation($file_scanner, $stmt, null, true), ); diff --git a/tests/AssertAnnotationTest.php b/tests/AssertAnnotationTest.php index 83945999d87..972e2e3d72f 100644 --- a/tests/AssertAnnotationTest.php +++ b/tests/AssertAnnotationTest.php @@ -90,6 +90,33 @@ function requiresString(string $_str): void {} $this->analyzeFile('somefile.php', new Context()); } + public function testAssertInvalidDocblockMessageDoesNotIncludeTrace(): void + { + $this->expectException(CodeException::class); + $this->expectExceptionMessageMatches( + '!^InvalidDocblock - ' . 'somefile\\.php:10:5 - Invalid @psalm-assert union type: Invalid type \'\\$expected\'$!', + ); + + $this->addFile( + 'somefile.php', + <<<'PHP' + analyzeFile('somefile.php', new Context()); + } + + public function providerValidCodeParse(): iterable { return [