Skip to content

Commit ec6900d

Browse files
committed
[Refactor] Enhance error reporting in KurrentDB usecases and error handling
Update withRethrowingError to include full type name in usage context Improve internalClientError messages by including original error details
1 parent 8efc7ad commit ec6900d

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

Sources/KurrentDB/Core/Additions/Usecase/StreamStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension StreamStream where Transport == HTTP2ClientTransport.Posix {
3232
try await client.runConnections()
3333
}
3434

35-
return try await withRethrowingError(usage: #function) {
35+
return try await withRethrowingError(usage: "\(Self.self)\(#function)") {
3636
try await send(connection: client, metadata: metadata, callOptions: callOptions)
3737
}
3838
}

Sources/KurrentDB/Core/Additions/Usecase/StreamUnary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension StreamUnary where Transport == HTTP2ClientTransport.Posix {
3232
}
3333

3434
package func perform(client: GRPCClient<HTTP2ClientTransport.Posix>, metadata: Metadata, callOptions: CallOptions) async throws(KurrentError) -> Response {
35-
try await withRethrowingError(usage: #function) {
35+
try await withRethrowingError(usage: "\(Self.self)\(#function)") {
3636
try await withThrowingTaskGroup(of: Void.self) { group in
3737
group.addTask {
3838
try await client.runConnections()

Sources/KurrentDB/Core/Additions/Usecase/UnaryStream.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension UnaryStream where Transport == HTTP2ClientTransport.Posix, Responses =
1616
try await client.runConnections()
1717
}
1818

19-
return try await withRethrowingError(usage: #function) {
19+
return try await withRethrowingError(usage: "\(Self.self)\(#function)") {
2020
let metadata = Metadata(from: node.settings)
2121
let request = try request(metadata: metadata)
2222
return try await send(connection: client, request: request, callOptions: callOptions)
@@ -52,7 +52,7 @@ extension UnaryStream where Transport == HTTP2ClientTransport.Posix {
5252
try await client.runConnections()
5353
}
5454

55-
return try await withRethrowingError(usage: #function) {
55+
return try await withRethrowingError(usage: "\(Self.self)\(#function)") {
5656
let request = try request(metadata: metadata)
5757
return try await send(connection: client, request: request, callOptions: callOptions)
5858
}

Sources/KurrentDB/Core/Additions/Usecase/UnaryUnary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension UnaryUnary where Transport == HTTP2ClientTransport.Posix {
3737
}
3838

3939
package func perform(client: GRPCClient<HTTP2ClientTransport.Posix>, metadata: Metadata, callOptions: CallOptions) async throws(KurrentError) -> Response {
40-
try await withRethrowingError(usage: #function) {
40+
try await withRethrowingError(usage: "\(Self.self)\(#function)") {
4141
try await withThrowingTaskGroup(of: Void.self) { group in
4242
group.addTask {
4343
try await client.runConnections()

Sources/KurrentDB/Core/Error/KurrentError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func withRethrowingError<T>(usage: String, action: @Sendable () async throws ->
154154
} catch let error as RPCError {
155155
try error.rethrow(usage: usage, origin: error)
156156
} catch {
157-
throw .internalClientError(reason: "\(usage) failed.")
157+
throw .internalClientError(reason: "\(usage) failed. error: \(error)")
158158
}
159159
throw .internalClientError(reason: "\(usage) failed.")
160160
}
@@ -167,7 +167,7 @@ func withRethrowingError<T>(usage: String, action: @Sendable () throws -> T) thr
167167
} catch let error as RPCError {
168168
try error.rethrow(usage: usage, origin: error)
169169
} catch {
170-
throw .internalClientError(reason: "\(usage) failed.")
170+
throw .internalClientError(reason: "\(usage) failed. error: \(error)")
171171
}
172172
throw .internalClientError(reason: "\(usage) failed.")
173173
}

0 commit comments

Comments
 (0)