1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-11 17:09:47 +01:00

Improve error message

This commit is contained in:
Aaron Piotrowski 2019-09-26 17:24:16 -05:00
parent 31b739bc77
commit b056da210d
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 7 additions and 3 deletions

View File

@ -21,7 +21,7 @@ final class ConnectionConfig extends SqlConnectionConfig
return new self( return new self(
$parts["host"], $parts["host"],
$parts["port"] ?? self::DEFAULT_PORT, (int) ($parts["port"] ?? self::DEFAULT_PORT),
$parts["user"] ?? null, $parts["user"] ?? null,
$parts["password"] ?? null, $parts["password"] ?? null,
$parts["db"] ?? null $parts["db"] ?? null

View File

@ -3,7 +3,7 @@
namespace Amp\Postgres; namespace Amp\Postgres;
use Amp\Promise; use Amp\Promise;
use Amp\Sql\ConnectionConfig; use Amp\Sql\ConnectionConfig as SqlConnectionConfig;
use Amp\Sql\Connector; use Amp\Sql\Connector;
use Amp\Sql\FailureException; use Amp\Sql\FailureException;
use Amp\TimeoutCancellationToken; use Amp\TimeoutCancellationToken;
@ -30,8 +30,12 @@ final class TimeoutConnector implements Connector
* *
* @throws \Error If neither ext-pgsql or pecl-pq is loaded. * @throws \Error If neither ext-pgsql or pecl-pq is loaded.
*/ */
public function connect(ConnectionConfig $connectionConfig): Promise public function connect(SqlConnectionConfig $connectionConfig): Promise
{ {
if (!$connectionConfig instanceof ConnectionConfig) {
throw new \TypeError(\sprintf("Must provide an instance of %s to Postgres connectors", ConnectionConfig::class));
}
$token = new TimeoutCancellationToken($this->timeout); $token = new TimeoutCancellationToken($this->timeout);
if (\extension_loaded("pq")) { if (\extension_loaded("pq")) {