From d31f4a249a2c7eef373f044e781b2f89f7e5e64d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 31 Jul 2018 01:42:27 -0600 Subject: [PATCH] [EventLoopFuture] Ensure client #file/#line are forwarded in `mapIfError`. (#533) Motivation: This ensures that the client's context information will be propagated into the promise which is implicitly created by thenIfError(). Without this, if that promise leaked the client would only see information about where it was allocated inside of NIO, which is not helpful. Modifications: Propagate #file/#line. Result: Client's will see a #file/#line in their code, rather than something like: ``` Fatal error: leaking promise created at (file: ".../.build/checkouts/swift-nio.git-bla/Sources/NIO/EventLoopFuture.swift", line: 583) ``` --- Sources/NIO/EventLoopFuture.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/NIO/EventLoopFuture.swift b/Sources/NIO/EventLoopFuture.swift index 6b90e60c7..3fbe57c52 100644 --- a/Sources/NIO/EventLoopFuture.swift +++ b/Sources/NIO/EventLoopFuture.swift @@ -580,7 +580,9 @@ extension EventLoopFuture { /// a new value lifted into a new `EventLoopFuture`. /// - returns: A future that will receive the recovered value. public func mapIfError(file: StaticString = #file, line: UInt = #line, _ callback: @escaping (Error) -> T) -> EventLoopFuture { - return thenIfError { return EventLoopFuture(eventLoop: self.eventLoop, result: callback($0), file: file, line: line) } + return thenIfError(file: file, line: line) { + return EventLoopFuture(eventLoop: self.eventLoop, result: callback($0), file: file, line: line) + } }