Improve error handling in answerHost (#226)

Refactor `answerHost` to throw descriptive `DNSResolverError` instances
instead of returning nil when IP allocation or parsing fails.
This commit is contained in:
Eliseo Martelli
2025-06-27 10:29:25 -07:00
committed by GitHub
parent de2be705de
commit b5589f7f8c
+7 -4
View File
@@ -80,12 +80,15 @@ struct ContainerDNSHandler: DNSHandler {
}
let components = ipAllocation.address.split(separator: "/")
guard components.count > 0 else {
return nil
guard !components.isEmpty else {
throw DNSResolverError.serverError("Invalid IP format: empty address")
}
guard let ip = IPv4(String(components[0])) else {
return nil
let ipString = String(components[0])
guard let ip = IPv4(ipString) else {
throw DNSResolverError.serverError("Failed to parse IP address: \(ipString)")
}
return HostRecord<IPv4>(name: question.name, ttl: ttl, ip: ip)
}
}