Repository: vapor/vapor
File: Sources/Development/routes.swift (Swift)

Code before:
                        buffer: buffer,
                        eventLoop: req.eventLoop
                    )
                case .error(let drainError):
                    var fileHandleError: Error?
                    do {
                        try fileHandle.close()
                    } catch {
                        fileHandleError = error
                    }
                    if let fileHandleError = fileHandleError {
                        promise.fail(BodyStreamWritingToDiskError.multipleFailures([
                            .fileHandleClosedFailure(fileHandleError),
                            .streamFailure(drainError)
                        ]))
                    } else {
                        promise.fail(BodyStreamWritingToDiskError.streamFailure(drainError))
                    }
                    return req.eventLoop.makeSucceededFuture(())
                case .end:
                    do {
                        try fileHandle.close()
                    } catch {
                        promise.fail(BodyStreamWritingToDiskError.fileHandleClosedFailure(error))
                    }
                    promise.succeed(.ok)
                    return req.eventLoop.makeSucceededFuture(())
                }
            }
            return promise.futureResult
        }
    }
}

struct TestError: AbortError, DebuggableError {
    var status: HTTPResponseStatus {
        .internalServerError
    }

    var reason: String {
        "This is a test."
    }

    var source: ErrorSource?
    var stackTrace: StackTrace?

    init(
        file: String = #file,
        function: String = #function,
        line: UInt = #line,
        column: UInt = #column,

Review comment (bug):
Even though it's acceptable to succeed a promise after faililng it, putting this in the `do` might be easier to understand for readers. 

Code after:
                        buffer: buffer,
                        eventLoop: req.eventLoop
                    )
                case .error(let drainError):
                    do {
                        try fileHandle.close()
                        promise.fail(BodyStreamWritingToDiskError.streamFailure(drainError))
                    } catch {
                        promise.fail(BodyStreamWritingToDiskError.multipleFailures([
                            .fileHandleClosedFailure(error),
                            .streamFailure(drainError)
                        ]))
                    }
                    return req.eventLoop.makeSucceededFuture(())
                case .end:
                    do {
                        try fileHandle.close()
                        promise.succeed(.ok)
                    } catch {
                        promise.fail(BodyStreamWritingToDiskError.fileHandleClosedFailure(error))
                    }
                    return req.eventLoop.makeSucceededFuture(())
                }
            }
            return promise.futureResult
        }
    }
}

struct TestError: AbortError, DebuggableError {
    var status: HTTPResponseStatus {
        .internalServerError
    }

    var reason: String {
        "This is a test."
    }

    var source: ErrorSource?
    var stackTrace: StackTrace?

    init(
        file: String = #file,
        function: String = #function,
        line: UInt = #line,
        column: UInt = #column,
        range: Range<UInt>? = nil,
        stackTrace: StackTrace? = .capture(skip: 1)
    ) {
        self.source = .init(
            file: file,