Skip to content

Commit

Permalink
Merge pull request #10679 from weirdan/8323-dont-show-backtrace-in-In…
Browse files Browse the repository at this point in the history
…validDocblock-issue-message
  • Loading branch information
weirdan committed Feb 8, 2024
2 parents aedea60 + 6b6bed5 commit f9a2314
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);

Expand Down
27 changes: 27 additions & 0 deletions tests/AssertAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
<?php
/**
* Asserts that two variables are not the same.
*
* @template T
* @param T $expected
* @param mixed $actual
* @psalm-assert !=$expected $actual
*/
function assertNotSame($expected, $actual) : void {}
PHP,
);

$this->analyzeFile('somefile.php', new Context());
}


public function providerValidCodeParse(): iterable
{
return [
Expand Down

0 comments on commit f9a2314

Please sign in to comment.