Skip to content

Commit

Permalink
Remove full DSNs from exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 3, 2023
1 parent 8560dc5 commit ba72f72
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Provider/AbstractProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract protected function getSupportedSchemes(): array;
protected function getUser(Dsn $dsn): string
{
if (null === $user = $dsn->getUser()) {
throw new IncompleteDsnException('User is not set.', $dsn->getOriginalDsn());
throw new IncompleteDsnException('User is not set.', $dsn->getScheme().'://'.$dsn->getHost());
}

return $user;
Expand Down
6 changes: 3 additions & 3 deletions Provider/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function __construct(string $dsn)
$this->originalDsn = $dsn;

if (false === $parsedDsn = parse_url($dsn)) {
throw new InvalidArgumentException(sprintf('The "%s" translation provider DSN is invalid.', $dsn));
throw new InvalidArgumentException('The translation provider DSN is invalid.');
}

if (!isset($parsedDsn['scheme'])) {
throw new InvalidArgumentException(sprintf('The "%s" translation provider DSN must contain a scheme.', $dsn));
throw new InvalidArgumentException('The translation provider DSN must contain a scheme.');
}
$this->scheme = $parsedDsn['scheme'];

if (!isset($parsedDsn['host'])) {
throw new InvalidArgumentException(sprintf('The "%s" translation provider DSN must contain a host (use "default" by default).', $dsn));
throw new InvalidArgumentException('The translation provider DSN must contain a host (use "default" by default).');
}
$this->host = $parsedDsn['host'];

Expand Down
6 changes: 3 additions & 3 deletions Tests/Provider/DsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@ public static function invalidDsnProvider(): iterable
{
yield [
'some://',
'The "some://" translation provider DSN is invalid.',
'The translation provider DSN is invalid.',
];

yield [
'//loco',
'The "//loco" translation provider DSN must contain a scheme.',
'The translation provider DSN must contain a scheme.',
];

yield [
'file:///some/path',
'The "file:///some/path" translation provider DSN must contain a host (use "default" by default).',
'The translation provider DSN must contain a host (use "default" by default).',
];
}

Expand Down

0 comments on commit ba72f72

Please sign in to comment.