Rename Error to MCPError (#44)
* Rename Error to MCPError * Conform MCPError to Swift.Error * Use unqualified Error instead of Swift.Error * Use unqualified MCPError instead of MCP.MCPError * Rename file back to Error.swift * Introduce top-level MCP namespace with nested Error typealias to provide deprecation notice for existing usage of MCP.Error * Fix markup for MCP enum warning
This commit is contained in:
parent
a9bcbf9ad9
commit
09da2a1c01
1 changed files with 108 additions and 88 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import Foundation
|
||||
import class Foundation.JSONEncoder
|
||||
import class Foundation.JSONDecoder
|
||||
import struct Foundation.Data
|
||||
import struct Foundation.POSIXError
|
||||
|
||||
import Logging
|
||||
|
||||
@testable import MCP
|
||||
|
|
@ -26,7 +30,7 @@ actor MockTransport: Transport {
|
|||
private var dataToReceive: [Data] = []
|
||||
private(set) var receivedMessages: [String] = []
|
||||
|
||||
private var dataStreamContinuation: AsyncThrowingStream<Data, Swift.Error>.Continuation?
|
||||
private var dataStreamContinuation: AsyncThrowingStream<Data, Error>.Continuation?
|
||||
|
||||
var shouldFailConnect = false
|
||||
var shouldFailSend = false
|
||||
|
|
@ -37,7 +41,7 @@ actor MockTransport: Transport {
|
|||
|
||||
public func connect() async throws {
|
||||
if shouldFailConnect {
|
||||
throw Error.transportError(POSIXError(.ECONNREFUSED))
|
||||
throw MCPError.transportError(POSIXError(.ECONNREFUSED))
|
||||
}
|
||||
isConnected = true
|
||||
}
|
||||
|
|
@ -50,13 +54,13 @@ actor MockTransport: Transport {
|
|||
|
||||
public func send(_ message: Data) async throws {
|
||||
if shouldFailSend {
|
||||
throw Error.transportError(POSIXError(.EIO))
|
||||
throw MCPError.transportError(POSIXError(.EIO))
|
||||
}
|
||||
sentData.append(message)
|
||||
}
|
||||
|
||||
public func receive() -> AsyncThrowingStream<Data, Swift.Error> {
|
||||
return AsyncThrowingStream<Data, Swift.Error> { continuation in
|
||||
public func receive() -> AsyncThrowingStream<Data, Error> {
|
||||
return AsyncThrowingStream<Data, Error> { continuation in
|
||||
dataStreamContinuation = continuation
|
||||
for message in dataToReceive {
|
||||
continuation.yield(message)
|
||||
|
|
@ -76,7 +80,7 @@ actor MockTransport: Transport {
|
|||
shouldFailSend = shouldFail
|
||||
}
|
||||
|
||||
func queue<M: MCP.Method>(request: Request<M>) throws {
|
||||
func queue<M: Method>(request: Request<M>) throws {
|
||||
let data = try encoder.encode(request)
|
||||
if let continuation = dataStreamContinuation {
|
||||
continuation.yield(data)
|
||||
|
|
@ -85,12 +89,12 @@ actor MockTransport: Transport {
|
|||
}
|
||||
}
|
||||
|
||||
func queue<M: MCP.Method>(response: Response<M>) throws {
|
||||
func queue<M: Method>(response: Response<M>) throws {
|
||||
let data = try encoder.encode(response)
|
||||
dataToReceive.append(data)
|
||||
}
|
||||
|
||||
func queue<N: MCP.Notification>(notification: Message<N>) throws {
|
||||
func queue<N: Notification>(notification: Message<N>) throws {
|
||||
let data = try encoder.encode(notification)
|
||||
dataToReceive.append(data)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue