From f2ed903c0a522593c7c552fa5b1e20dfe7ba1ec6 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 16 Dec 2024 23:20:18 -0600 Subject: [PATCH] Fix #120: Incorrect error message on missing domain (#121) --- src/Rfc1035StubDnsResolver.php | 14 ++++++++------ test/Rfc1035StubResolverTest.php | 11 +++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Rfc1035StubDnsResolver.php b/src/Rfc1035StubDnsResolver.php index 7227434..cfb8536 100644 --- a/src/Rfc1035StubDnsResolver.php +++ b/src/Rfc1035StubDnsResolver.php @@ -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; } diff --git a/test/Rfc1035StubResolverTest.php b/test/Rfc1035StubResolverTest.php index 6f24cfe..01ce5b0 100644 --- a/test/Rfc1035StubResolverTest.php +++ b/test/Rfc1035StubResolverTest.php @@ -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; @@ -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;