@@ -207,6 +207,10 @@ extension DistributedActorSystem {
207207 /// some other mismatch between them happens. In general, this
208208 /// method is allowed to throw in any situation that might otherwise
209209 /// result in an illegal or unexpected invocation being performed.
210+ ///
211+ /// Throws ``ExecuteDistributedTargetMissingAccessorError`` if the `target`
212+ /// does not resolve to a valid distributed function accessor, i.e. the
213+ /// call identifier is incorrect, corrupted, or simply not present in this process.
210214 public func executeDistributedTarget< Act> (
211215 on actor : Act ,
212216 target: RemoteCallTarget ,
@@ -242,7 +246,8 @@ extension DistributedActorSystem {
242246 let subs = try invocationDecoder. decodeGenericSubstitutions ( )
243247 if subs. isEmpty {
244248 throw ExecuteDistributedTargetError (
245- message: " Cannot call generic method without generic argument substitutions " )
249+ message: " Cannot call generic method without generic argument substitutions " ,
250+ errorCode: . missingGenericSubstitutions)
246251 }
247252
248253 substitutionsBuffer = . allocate( capacity: subs. count)
@@ -256,7 +261,8 @@ extension DistributedActorSystem {
256261 genericArguments: substitutionsBuffer!)
257262 if numWitnessTables < 0 {
258263 throw ExecuteDistributedTargetError (
259- message: " Generic substitutions \( subs) do not satisfy generic requirements of \( target) ( \( targetName) ) " )
264+ message: " Generic substitutions \( subs) do not satisfy generic requirements of \( target) ( \( targetName) ) " ,
265+ errorCode: . invalidGenericSubstitutions)
260266 }
261267 }
262268
@@ -270,7 +276,8 @@ extension DistributedActorSystem {
270276 Failed to decode distributed invocation target expected parameter count,
271277 error code: \( paramCount)
272278 mangled name: \( targetName)
273- """ )
279+ """ ,
280+ errorCode: . invalidParameterCount)
274281 }
275282
276283 // Prepare buffer for the parameter types to be decoded into:
@@ -295,7 +302,8 @@ extension DistributedActorSystem {
295302 Failed to decode the expected number of params of distributed invocation target, error code: \( decodedNum)
296303 (decoded: \( decodedNum) , expected params: \( paramCount)
297304 mangled name: \( targetName)
298- """ )
305+ """ ,
306+ errorCode: . invalidParameterCount)
299307 }
300308
301309 // Copy the types from the buffer into a Swift Array
@@ -316,12 +324,14 @@ extension DistributedActorSystem {
316324 genericEnv: genericEnv,
317325 genericArguments: substitutionsBuffer) else {
318326 throw ExecuteDistributedTargetError (
319- message: " Failed to decode distributed target return type " )
327+ message: " Failed to decode distributed target return type " ,
328+ errorCode: . typeDeserializationFailure)
320329 }
321330
322331 guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: allocateReturnTypeBuffer) else {
323332 throw ExecuteDistributedTargetError (
324- message: " Failed to allocate buffer for distributed target return type " )
333+ message: " Failed to allocate buffer for distributed target return type " ,
334+ errorCode: . typeDeserializationFailure)
325335 }
326336
327337 func destroyReturnTypeBuffer< R> ( _: R . Type ) {
@@ -567,12 +577,49 @@ public protocol DistributedTargetInvocationResultHandler {
567577@available ( SwiftStdlib 5 . 7 , * )
568578public protocol DistributedActorSystemError : Error { }
569579
580+ /// Error thrown by ``DistributedActorSystem/executeDistributedTarget(on:target:invocationDecoder:handler:)``.
581+ ///
582+ /// Inspect the ``errorCode`` for details about the underlying reason this error was thrown.
570583@available ( SwiftStdlib 5 . 7 , * )
571584public struct ExecuteDistributedTargetError : DistributedActorSystemError {
572- let message : String
585+ public let errorCode : ErrorCode
586+ public let message : String
587+
588+ public enum ErrorCode {
589+ /// Unable to resolve the target identifier to a function accessor.
590+ /// This can happen when the identifier is corrupt, illegal, or wrong in the
591+ /// sense that the caller and callee do not have the called function recorded
592+ /// using the same identifier.
593+ case targetAccessorNotFound
594+
595+ /// Call target has different number of parameters than arguments
596+ /// provided by the invocation decoder.
597+ case invalidParameterCount
598+
599+ /// Target expects generic environment information, but invocation decoder
600+ /// provided no generic substitutions.
601+ case missingGenericSubstitutions
602+
603+ /// Generic substitutions provided by invocation decoder are incompatible
604+ /// with target of the call. E.g. the generic requirements on the actual
605+ /// target could not be fulfilled by the obtained generic substitutions.
606+ case invalidGenericSubstitutions
607+
608+ // Failed to deserialize type or obtain type information for call.
609+ case typeDeserializationFailure
610+
611+ /// A general issue during the execution of the distributed call target occurred.
612+ case other
613+ }
573614
574615 public init ( message: String ) {
575616 self . message = message
617+ self . errorCode = . other
618+ }
619+
620+ public init ( message: String , errorCode: ErrorCode ) {
621+ self . message = message
622+ self . errorCode = errorCode
576623 }
577624}
578625
0 commit comments