Skip to content

Commit 8f8557b

Browse files
authored
Remove PSQLError.Code.clientClosesConnection (#400)
1 parent 9a02d74 commit 8f8557b

File tree

5 files changed

+11
-21
lines changed

5 files changed

+11
-21
lines changed

Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ struct ConnectionStateMachine {
550550
// check if we are quiescing. if so fail task immidiatly
551551
switch self.quiescingState {
552552
case .quiescing:
553-
psqlErrror = PSQLError.clientClosesConnection(underlying: nil)
553+
psqlErrror = PSQLError.clientClosedConnection(underlying: nil)
554554

555555
case .notQuiescing:
556556
switch self.state {
@@ -570,7 +570,7 @@ struct ConnectionStateMachine {
570570
return self.executeTask(task)
571571

572572
case .closing(let error):
573-
psqlErrror = PSQLError.clientClosesConnection(underlying: error)
573+
psqlErrror = PSQLError.clientClosedConnection(underlying: error)
574574

575575
case .closed(clientInitiated: true, error: let error):
576576
psqlErrror = PSQLError.clientClosedConnection(underlying: error)
@@ -1033,7 +1033,7 @@ extension ConnectionStateMachine {
10331033
}
10341034

10351035
return false
1036-
case .clientClosesConnection, .clientClosedConnection:
1036+
case .clientClosedConnection:
10371037
preconditionFailure("A pure client error was thrown directly in PostgresConnection, this shouldn't happen")
10381038
case .serverClosedConnection:
10391039
return true

Sources/PostgresNIO/New/PSQLError.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public struct PSQLError: Error {
1818

1919
case queryCancelled
2020
case tooManyParameters
21-
case clientClosesConnection
2221
case clientClosedConnection
2322
case serverClosedConnection
2423
case connectionError
@@ -46,16 +45,15 @@ public struct PSQLError: Error {
4645
public static let invalidCommandTag = Self(.invalidCommandTag)
4746
public static let queryCancelled = Self(.queryCancelled)
4847
public static let tooManyParameters = Self(.tooManyParameters)
49-
public static let clientClosesConnection = Self(.clientClosesConnection)
5048
public static let clientClosedConnection = Self(.clientClosedConnection)
5149
public static let serverClosedConnection = Self(.serverClosedConnection)
5250
public static let connectionError = Self(.connectionError)
5351
public static let uncleanShutdown = Self.init(.uncleanShutdown)
5452
public static let listenFailed = Self.init(.listenFailed)
5553
public static let unlistenFailed = Self.init(.unlistenFailed)
5654

57-
@available(*, deprecated, renamed: "clientClosesConnection")
58-
public static let connectionQuiescing = Self.clientClosesConnection
55+
@available(*, deprecated, renamed: "clientClosedConnection")
56+
public static let connectionQuiescing = Self.clientClosedConnection
5957

6058
@available(*, deprecated, message: "Use the more specific `serverClosedConnection` or `clientClosedConnection` instead")
6159
public static let connectionClosed = Self.serverClosedConnection
@@ -86,8 +84,6 @@ public struct PSQLError: Error {
8684
return "queryCancelled"
8785
case .tooManyParameters:
8886
return "tooManyParameters"
89-
case .clientClosesConnection:
90-
return "clientClosesConnection"
9187
case .clientClosedConnection:
9288
return "clientClosedConnection"
9389
case .serverClosedConnection:
@@ -387,12 +383,6 @@ public struct PSQLError: Error {
387383
return new
388384
}
389385

390-
static func clientClosesConnection(underlying: Error?) -> PSQLError {
391-
var error = PSQLError(code: .clientClosesConnection)
392-
error.underlying = underlying
393-
return error
394-
}
395-
396386
static func clientClosedConnection(underlying: Error?) -> PSQLError {
397387
var error = PSQLError(code: .clientClosedConnection)
398388
error.underlying = underlying

Sources/PostgresNIO/New/PostgresChannelHandler.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,10 @@ final class PostgresChannelHandler: ChannelDuplexHandler {
576576
}
577577

578578
// 3. fire an error
579-
context.fireErrorCaught(cleanup.error)
580-
579+
if cleanup.error.code != .clientClosedConnection {
580+
context.fireErrorCaught(cleanup.error)
581+
}
582+
581583
// 4. close the connection or fire channel inactive
582584
switch cleanup.action {
583585
case .close:

Sources/PostgresNIO/Postgres+PSQLCompat.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ extension PSQLError {
3737
return self.underlying ?? self
3838
case .tooManyParameters, .invalidCommandTag:
3939
return self
40-
case .clientClosesConnection,
41-
.clientClosedConnection,
40+
case .clientClosedConnection,
4241
.serverClosedConnection:
4342
return PostgresError.connectionClosed
4443
case .connectionError:

Tests/PostgresNIOTests/New/PostgresChannelHandlerTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class PostgresChannelHandlerTests: XCTestCase {
2525
handler
2626
], loop: self.eventLoop)
2727
defer {
28-
do { try embedded.finish() }
29-
catch { print("\(String(reflecting: error))") }
28+
XCTAssertNoThrow({ try embedded.finish() })
3029
}
3130

3231
var maybeMessage: PostgresFrontendMessage?

0 commit comments

Comments
 (0)