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.
This commit is contained in:
Cory Benfield 2019-04-16 12:29:40 +01:00 committed by Johannes Weiss
parent 442e1807df
commit 687e79828a
1 changed files with 3 additions and 3 deletions

View File

@ -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()
}
}
}