@@ -207,6 +207,10 @@ extension DistributedActorSystem {
207
207
/// some other mismatch between them happens. In general, this
208
208
/// method is allowed to throw in any situation that might otherwise
209
209
/// 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.
210
214
public func executeDistributedTarget< Act> (
211
215
on actor : Act ,
212
216
target: RemoteCallTarget ,
@@ -242,7 +246,8 @@ extension DistributedActorSystem {
242
246
let subs = try invocationDecoder. decodeGenericSubstitutions ( )
243
247
if subs. isEmpty {
244
248
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)
246
251
}
247
252
248
253
substitutionsBuffer = . allocate( capacity: subs. count)
@@ -256,7 +261,8 @@ extension DistributedActorSystem {
256
261
genericArguments: substitutionsBuffer!)
257
262
if numWitnessTables < 0 {
258
263
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)
260
266
}
261
267
}
262
268
@@ -270,7 +276,8 @@ extension DistributedActorSystem {
270
276
Failed to decode distributed invocation target expected parameter count,
271
277
error code: \( paramCount)
272
278
mangled name: \( targetName)
273
- """ )
279
+ """ ,
280
+ errorCode: . invalidParameterCount)
274
281
}
275
282
276
283
// Prepare buffer for the parameter types to be decoded into:
@@ -295,7 +302,8 @@ extension DistributedActorSystem {
295
302
Failed to decode the expected number of params of distributed invocation target, error code: \( decodedNum)
296
303
(decoded: \( decodedNum) , expected params: \( paramCount)
297
304
mangled name: \( targetName)
298
- """ )
305
+ """ ,
306
+ errorCode: . invalidParameterCount)
299
307
}
300
308
301
309
// Copy the types from the buffer into a Swift Array
@@ -316,12 +324,14 @@ extension DistributedActorSystem {
316
324
genericEnv: genericEnv,
317
325
genericArguments: substitutionsBuffer) else {
318
326
throw ExecuteDistributedTargetError (
319
- message: " Failed to decode distributed target return type " )
327
+ message: " Failed to decode distributed target return type " ,
328
+ errorCode: . typeDeserializationFailure)
320
329
}
321
330
322
331
guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: allocateReturnTypeBuffer) else {
323
332
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)
325
335
}
326
336
327
337
func destroyReturnTypeBuffer< R> ( _: R . Type ) {
@@ -567,12 +577,49 @@ public protocol DistributedTargetInvocationResultHandler {
567
577
@available ( SwiftStdlib 5 . 7 , * )
568
578
public protocol DistributedActorSystemError : Error { }
569
579
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.
570
583
@available ( SwiftStdlib 5 . 7 , * )
571
584
public 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
+ }
573
614
574
615
public init ( message: String ) {
575
616
self . message = message
617
+ self . errorCode = . other
618
+ }
619
+
620
+ public init ( message: String , errorCode: ErrorCode ) {
621
+ self . message = message
622
+ self . errorCode = errorCode
576
623
}
577
624
}
578
625
0 commit comments