Skip to content

Commit

Permalink
Remove the temporary workaround for PSQLError descriptions (#245)
Browse files Browse the repository at this point in the history
* Revert "Temporary bandaid workaround for lack of PSQLError usefulness (#244)"

This reverts commit 875e8c1.

* Ditch old and badly outdated file
  • Loading branch information
gwynne committed Jun 9, 2023
1 parent 875e8c1 commit a88d025
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 68 deletions.
2 changes: 0 additions & 2 deletions Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
let string = searchPath.map { #""\#($0)""# }.joined(separator: ", ")
return conn.simpleQuery("SET search_path = \(string)").map { _ in conn }
}
.flatMapErrorThrowing { try PostgresDataTranslation.applyPSQLErrorBandaidIfNeeded(for: $0) }
} else {
return connectionFuture
.flatMapErrorThrowing { try PostgresDataTranslation.applyPSQLErrorBandaidIfNeeded(for: $0) }
}
}
}
Expand Down
35 changes: 0 additions & 35 deletions Sources/PostgresKit/PostgresDatabase+SQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,9 @@ extension _PostgresSQLDatabase: SQLDatabase, PostgresDatabase {

func send(_ request: any PostgresRequest, logger: Logger) -> EventLoopFuture<Void> {
self.database.send(request, logger: logger)
.flatMapErrorThrowing { try PostgresDataTranslation.applyPSQLErrorBandaidIfNeeded(for: $0) }
}

func withConnection<T>(_ closure: @escaping (PostgresConnection) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
self.database.withConnection(closure)
.flatMapErrorThrowing { try PostgresDataTranslation.applyPSQLErrorBandaidIfNeeded(for: $0) }
}
}

// This can go away as soon as https://github.com/vapor/postgres-nio/pull/360 is merged.
struct ExpressivePSQLError: Error, CustomStringConvertible, CustomDebugStringConvertible {
let underlyingError: PSQLError
var description: String { "Database error" }
var debugDescription: String {
var desc = #"PSQLError(code: \#(self.underlyingError.code)"#
if let serverInfo = self.underlyingError.serverInfo {
desc.append(", serverInfo: [")
desc.append(["localizedSeverity": PSQLError.ServerInfo.Field.localizedSeverity, "severity": .severity, "sqlState": .sqlState, "message": .message, "detail": .detail, "hint": .hint, "position": .position, "internalPosition": .internalPosition, "internalQuery": .internalQuery, "locationContext": .locationContext, "schemaName": .schemaName, "tableName": .tableName, "columnName": .columnName, "dataTypeName": .dataTypeName, "constraintName": .constraintName, "file": .file, "line": .line, "routine": .routine].compactMap { name, field in serverInfo[field].map { "\(name): \($0)" } }.joined(separator: ", "))
desc.append("]")
}
if let underlying = self.underlyingError.underlying { desc.append(", underlying: \(String(reflecting: underlying))") }
if let file = self.underlyingError.file {
desc.append(", triggeredFromRequestInFile: \(file)")
if let line = self.underlyingError.line { desc.append(", line: \(line)") }
}
if let query = self.underlyingError.query { desc.append(", query: \(query)") }
desc.append(")")
return desc
}
}

extension PostgresDataTranslation {
@usableFromInline
static func applyPSQLErrorBandaidIfNeeded(for error: any Error) throws -> Never {
if let psqlError = error as? PSQLError {
throw ExpressivePSQLError(underlyingError: psqlError)
} else {
throw error
}
}
}
31 changes: 0 additions & 31 deletions docker-compose.yml

This file was deleted.

0 comments on commit a88d025

Please sign in to comment.