Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show backtrace in InvalidDocblock issue message #10679

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't show backtrace in InvalidDocblock issue message
Fixes #8323
weirdan committed Feb 8, 2024

Verified

This commit was signed with the committer’s verified signature.
weirdan Bruce Weirdan
commit 6b6bed5850d6401b8cfe585b3ad7505ffea96dd2
Original file line number Diff line number Diff line change
@@ -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),
);

27 changes: 27 additions & 0 deletions tests/AssertAnnotationTest.php
Original file line number Diff line number Diff line change
@@ -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 [