When receiving the response NXDOMAIN, AsyncDNSResolver throws .internalError, requiring callers to code like this:
var records: [SRVRecord]
do {
records = try await Self.resolver.querySRV(name: srvName)
} catch let error as AsyncDNSResolver.Error where error.code == .internalError {
// Catch NXDOMAIN, which is erroneously reported as `.internalError`.
// NXDOMAIN and `results==[]` (commonly called "NODATA") both indicate affirmative nonexistence.
// Hopefully other common errors aren't `.internalError` as that may cause weird behavior here.
records = []
} catch let error {
// Catch timeouts and other transient network errors.
throw error
}
Adding an exception for .nxDomain might be a tempting solution, but it would break existing workarounds like the above. But it can't be conflated into .internalError; doing so as it does now is clearly a bug.
I suggest updating queryXXX calls to return [] when the response is coded NXDOMAIN. This makes sense because the distinction between the DNS entry existing only by different types (commonly "NODATA") vs not existing at all (NXDOMAIN) isn't a useful distinction, so they can be treated the same. Returning [] simplifies clients by not needing the first catch case shown above, and sidesteps potential compatibility issues for existing callers.
When receiving the response NXDOMAIN, AsyncDNSResolver throws
.internalError, requiring callers to code like this:Adding an exception for
.nxDomainmight be a tempting solution, but it would break existing workarounds like the above. But it can't be conflated into.internalError; doing so as it does now is clearly a bug.I suggest updating queryXXX calls to return
[]when the response is coded NXDOMAIN. This makes sense because the distinction between the DNS entry existing only by different types (commonly "NODATA") vs not existing at all (NXDOMAIN) isn't a useful distinction, so they can be treated the same. Returning [] simplifies clients by not needing the first catch case shown above, and sidesteps potential compatibility issues for existing callers.