Skip to content

Commit

Permalink
add custom string convertible conformance to OracleSQLError.ServerInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetodream committed Oct 19, 2024
1 parent 6ffe70a commit 4ed48f5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
Expand Down Expand Up @@ -104,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5",
"version" : "1.3.2"
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
"version" : "1.4.0"
}
}
],
Expand Down
6 changes: 5 additions & 1 deletion Sources/OracleNIO/OracleSQLError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public struct OracleSQLError: Sendable, Error {
}
}

public struct ServerInfo: Sendable {
public struct ServerInfo: Sendable, CustomStringConvertible {
let underlying: OracleBackendMessage.BackendError

/// The error number/identifier.
Expand Down Expand Up @@ -244,6 +244,10 @@ public struct OracleSQLError: Sendable, Error {
init(_ underlying: OracleBackendMessage.BackendError) {
self.underlying = underlying
}

public var description: String {
message?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "ORA-\(number)"
}

Check warning on line 250 in Sources/OracleNIO/OracleSQLError.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OracleNIO/OracleSQLError.swift#L248-L250

Added lines #L248 - L250 were not covered by tests
}

public struct BatchError: Sendable {
Expand Down
42 changes: 42 additions & 0 deletions Tests/OracleNIOTests/OracleSQLErrorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the OracleNIO open source project
//
// Copyright (c) 2024 Timo Zacherl and the OracleNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS.md for the list of OracleNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

#if compiler(>=6.0)
import Testing

@testable import OracleNIO

@Suite
struct OracleSQLErrorTests {
@Test
func serverInfoDescription() {
let errorWithMessage = OracleSQLError.ServerInfo(
.init(
number: 1017,
isWarning: false,
message: "ORA-01017: invalid credential or not authorized; logon denied\n",
batchErrors: []
))
#expect(
String(describing: errorWithMessage) == "ORA-01017: invalid credential or not authorized; logon denied")
let errorWithoutMessage = OracleSQLError.ServerInfo(
.init(
number: 1017,
isWarning: false,
batchErrors: []
))
#expect(String(describing: errorWithoutMessage) == "ORA-1017")
}
}
#endif

0 comments on commit 4ed48f5

Please sign in to comment.