Provide descriptions for EventLoopError (#1381)

Motivation:

EventLoopError does not conform to CustomStringConvertible. When these
errors appear in programs depending on NIO the source of the error is
non-obvious to the user.

EventLoopError.shutdown, for example, would appear in logs as
"shutdown" with no indication that it was the event loop being referred
to.

Modifications:

- Conform EventLoopError to CustomStringConvertible

Result:

- More helpful error descriptions for EventLoopError
This commit is contained in:
George Barnett 2020-02-05 11:26:41 +00:00 committed by GitHub
parent c92a9c638c
commit a678727747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -1027,3 +1027,18 @@ public enum EventLoopError: Error {
/// Shutting down the `EventLoop` failed.
case shutdownFailed
}
extension EventLoopError: CustomStringConvertible {
public var description: String {
switch self {
case .unsupportedOperation:
return "EventLoopError: the executed operation is not supported by the event loop"
case .cancelled:
return "EventLoopError: the scheduled task was cancelled"
case .shutdown:
return "EventLoopError: the event loop is shutdown"
case .shutdownFailed:
return "EventLoopError: failed to shutdown the event loop"
}
}
}