From 687e79828a40978292a89eb0d1caec28571d8ca2 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 16 Apr 2019 12:29:40 +0100 Subject: [PATCH] Remove unnecessary traps. (#37) Motivation: At least in some cases it's possible to have a local or remote address that we cannot represent in a SocketAddress. In the face of that, we were unnecessarily crashing. Crashes should probably be avoided there. Modifications: - Replace the crashes with throws. Result: Fewer crashes, more nils. --- Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift b/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift index 8b87de3..d550c14 100644 --- a/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift +++ b/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift @@ -97,11 +97,11 @@ extension SocketAddress { case .unix(let path): self = try .init(unixDomainSocketPath: path) case .service: - preconditionFailure("Cannot represent service addresses in SocketAddress") + throw NIOTSErrors.UnableToResolveEndpoint() case .hostPort(_, _): - preconditionFailure("Cannot represent unknown host in SocketAddress") + throw NIOTSErrors.UnableToResolveEndpoint() @unknown default: - preconditionFailure("cannot create SocketAddress from unknown representation") + throw NIOTSErrors.UnableToResolveEndpoint() } } }