diff --git a/Sources/DistributedActors/ActorRef+Ask.swift b/Sources/DistributedActors/ActorRef+Ask.swift index 4344fd82d..9f9441684 100644 --- a/Sources/DistributedActors/ActorRef+Ask.swift +++ b/Sources/DistributedActors/ActorRef+Ask.swift @@ -71,11 +71,11 @@ extension _ActorRef: ReceivesQuestions { _ makeQuestion: @escaping (_ActorRef) -> Question ) -> AskResponse { guard let system = self._system else { - return .completed(.failure(AskError.systemAlreadyShutDown)) + return .completed(.failure(RemoteCallError.clusterAlreadyShutDown)) } if system.isShuttingDown { - return .completed(.failure(AskError.systemAlreadyShutDown)) + return .completed(.failure(RemoteCallError.clusterAlreadyShutDown)) } do { @@ -147,11 +147,6 @@ enum AskResponse { case nioFuture(EventLoopFuture) } -enum AskError: DistributedActorSystemError, Error { - case timedOut(TimeoutError) - case systemAlreadyShutDown -} - extension AskResponse { /// Blocks and waits until there is a response or fails with an error. @available(*, deprecated, message: "Blocking API will be removed in favor of async await") @@ -203,7 +198,7 @@ extension AskResponse: _AsyncResult { let eventLoop = nioFuture.eventLoop let promise: EventLoopPromise = eventLoop.makePromise() let timeoutTask = eventLoop.scheduleTask(in: timeout.toNIO) { - promise.fail(AskError.timedOut(TimeoutError(message: "\(type(of: self)) timed out after \(timeout.prettyDescription)", timeout: timeout))) + promise.fail(RemoteCallError.timedOut(TimeoutError(message: "\(type(of: self)) timed out after \(timeout.prettyDescription)", timeout: timeout))) } nioFuture.whenFailure { timeoutTask.cancel() @@ -283,7 +278,7 @@ internal enum AskActor { Ask was initiated from function [\(function)] in [\(file):\(line)] and \ expected response of type [\(String(reflecting: ResponseType.self))]. """ - completable.fail(AskError.timedOut(TimeoutError(message: errorMessage, timeout: timeout))) + completable.fail(RemoteCallError.timedOut(TimeoutError(message: errorMessage, timeout: timeout))) // FIXME: Hack to stop from subReceive. Should we allow this somehow? // Maybe add a SubReceiveContext or similar? diff --git a/Sources/DistributedActors/Cluster/Reception/OperationLogDistributedReceptionist.swift b/Sources/DistributedActors/Cluster/Reception/OperationLogDistributedReceptionist.swift index 8bde47beb..9f58dfb3c 100644 --- a/Sources/DistributedActors/Cluster/Reception/OperationLogDistributedReceptionist.swift +++ b/Sources/DistributedActors/Cluster/Reception/OperationLogDistributedReceptionist.swift @@ -636,7 +636,7 @@ extension OpLogDistributedReceptionist { try await peerReceptionistRef.ackOps(until: latestAppliedSeqNrFromPeer, by: self) } catch { switch error { - case AskError.systemAlreadyShutDown: + case RemoteCallError.clusterAlreadyShutDown: // ignore silently; this often happens during tests when we terminate systems while interacting with them () default: diff --git a/Sources/DistributedActors/ClusterSystem.swift b/Sources/DistributedActors/ClusterSystem.swift index a2146084d..4b92a716c 100644 --- a/Sources/DistributedActors/ClusterSystem.swift +++ b/Sources/DistributedActors/ClusterSystem.swift @@ -951,7 +951,7 @@ extension ClusterSystem { Err: Error { guard let shell = self._cluster else { - throw AskError.systemAlreadyShutDown + throw RemoteCallError.clusterAlreadyShutDown } let recipient = _ActorRef(.remote(.init(shell: shell, address: actor.id._asRemote, system: self))) @@ -1065,8 +1065,9 @@ internal struct LazyStart { } } -enum RemoteCallError: Error { +enum RemoteCallError: DistributedActorSystemError, Error { case clusterAlreadyShutDown + case timedOut(TimeoutError) } /// Allows for configuring of remote calls by setting task-local values around a remote call being made. diff --git a/Tests/DistributedActorsTests/ActorAskTests.swift b/Tests/DistributedActorsTests/ActorAskTests.swift index 3911c7906..c2f1bec9e 100644 --- a/Tests/DistributedActorsTests/ActorAskTests.swift +++ b/Tests/DistributedActorsTests/ActorAskTests.swift @@ -66,8 +66,8 @@ final class ActorAskTests: ActorSystemXCTestCase { _ = try response.wait() } - guard case AskError.timedOut = error else { - throw testKit.fail("Expected AskError.timedOut, got \(error)") + guard case RemoteCallError.timedOut = error else { + throw testKit.fail("Expected RemoteCallError.timedOut, got \(error)") } } @@ -197,8 +197,8 @@ final class ActorAskTests: ActorSystemXCTestCase { try result.wait() } - guard case AskError.timedOut = error else { - throw testKit.fail("Expected AskError.timedOut, got \(error)") + guard case RemoteCallError.timedOut = error else { + throw testKit.fail("Expected RemoteCallError.timedOut, got \(error)") } } diff --git a/Tests/DistributedActorsTests/ClusterSystemTests.swift b/Tests/DistributedActorsTests/ClusterSystemTests.swift index 238bca60a..ce0000942 100644 --- a/Tests/DistributedActorsTests/ClusterSystemTests.swift +++ b/Tests/DistributedActorsTests/ClusterSystemTests.swift @@ -165,8 +165,8 @@ final class ClusterSystemTests: ActorSystemXCTestCase { } } - guard case AskError.timedOut(let timeoutError) = error else { - throw testKit.fail("Expected AskError.timedOut, got \(error)") + guard case RemoteCallError.timedOut(let timeoutError) = error else { + throw testKit.fail("Expected RemoteCallError.timedOut, got \(error)") } guard timeoutError.timeout == .seconds(1) else { throw testKit.fail("Expected timeout to be 1 second but was \(timeoutError.timeout)")