mirror of
https://github.com/apple/container.git
synced 2026-09-28 01:46:25 -04:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user