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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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