Skip to content

Commit

Permalink
Fix #120: Incorrect error message on missing domain
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Oct 28, 2024
1 parent b7515c1 commit 00bc06d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Rfc1035StubDnsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ public function resolve(string $name, ?int $typeRestriction = null, ?Cancellatio
}

return \array_merge(...$records);
} catch (MissingDnsRecordException) {
$alias = $this->searchForAliasRecord($searchName, $cancellation);
if ($alias !== null) {
$name = $alias;
}
continue;
} catch (DnsException $e) {
if ($e instanceof MissingDnsRecordException) {
$alias = $this->searchForAliasRecord($searchName, $cancellation);
if ($alias !== null) {
$name = $alias;
continue;
}
}

if ($searchIndex < \count($searchList) - 1 && $this->shouldRetry($e->getCode())) {
continue 2;
}
Expand Down
11 changes: 11 additions & 0 deletions test/Rfc1035StubResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Amp\Dns\DnsException;
use Amp\Dns\DnsRecord;
use Amp\Dns\InvalidNameException;
use Amp\Dns\MissingDnsRecordException;
use Amp\Dns\Rfc1035StubDnsResolver;
use Amp\Dns\StaticDnsConfigLoader;
use Amp\PHPUnit\AsyncTestCase;
Expand Down Expand Up @@ -95,6 +96,16 @@ public function testSearchListDomainDots(): void
], $this->cacheTrainer->getOperations());
}

public function testNonExistingDomain(): void
{
$this->dnsConfig = new DnsConfig(['8.8.8.8:53']);

$this->expectException(MissingDnsRecordException::class);
$this->expectExceptionMessage('No records returned for');

$this->whenResolve('not.existing.domain.com');
}

private function whenResolve(string $name, ?int $typeRestriction = null, ?Cancellation $cancellation = null): void
{
$configLoader = $this->dnsConfig !== null ? new StaticDnsConfigLoader($this->dnsConfig) : null;
Expand Down

0 comments on commit 00bc06d

Please sign in to comment.