@@ -251,7 +251,8 @@ extension DistributedActorSystem {
251
251
let subs = try invocationDecoder. decodeGenericSubstitutions ( )
252
252
if subs. isEmpty {
253
253
throw ExecuteDistributedTargetError (
254
- message: " Cannot call generic method without generic argument substitutions " )
254
+ message: " Cannot call generic method without generic argument substitutions " ,
255
+ errorCode: . missingGenericSubstitutions)
255
256
}
256
257
257
258
substitutionsBuffer = . allocate( capacity: subs. count)
@@ -265,7 +266,8 @@ extension DistributedActorSystem {
265
266
genericArguments: substitutionsBuffer!)
266
267
if numWitnessTables < 0 {
267
268
throw ExecuteDistributedTargetError (
268
- message: " Generic substitutions \( subs) do not satisfy generic requirements of \( target) ( \( targetName) ) " )
269
+ message: " Generic substitutions \( subs) do not satisfy generic requirements of \( target) ( \( targetName) ) " ,
270
+ errorCode: . invalidGenericSubstitutions)
269
271
}
270
272
}
271
273
@@ -279,7 +281,8 @@ extension DistributedActorSystem {
279
281
Failed to decode distributed invocation target expected parameter count,
280
282
error code: \( paramCount)
281
283
mangled name: \( targetName)
282
- """ )
284
+ """ ,
285
+ errorCode: . invalidParameterCount)
283
286
}
284
287
285
288
// Prepare buffer for the parameter types to be decoded into:
@@ -304,7 +307,8 @@ extension DistributedActorSystem {
304
307
Failed to decode the expected number of params of distributed invocation target, error code: \( decodedNum)
305
308
(decoded: \( decodedNum) , expected params: \( paramCount)
306
309
mangled name: \( targetName)
307
- """ )
310
+ """ ,
311
+ errorCode: . invalidParameterCount)
308
312
}
309
313
310
314
// Copy the types from the buffer into a Swift Array
@@ -325,12 +329,14 @@ extension DistributedActorSystem {
325
329
genericEnv: genericEnv,
326
330
genericArguments: substitutionsBuffer) else {
327
331
throw ExecuteDistributedTargetError (
328
- message: " Failed to decode distributed target return type " )
332
+ message: " Failed to decode distributed target return type " ,
333
+ errorCode: . typeDeserializationFailure)
329
334
}
330
335
331
336
guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: allocateReturnTypeBuffer) else {
332
337
throw ExecuteDistributedTargetError (
333
- message: " Failed to allocate buffer for distributed target return type " )
338
+ message: " Failed to allocate buffer for distributed target return type " ,
339
+ errorCode: . typeDeserializationFailure)
334
340
}
335
341
336
342
func destroyReturnTypeBuffer< R> ( _: R . Type ) {
@@ -576,19 +582,38 @@ public protocol DistributedTargetInvocationResultHandler {
576
582
@available ( SwiftStdlib 5 . 7 , * )
577
583
public protocol DistributedActorSystemError : Error { }
578
584
585
+ /// Error thrown by ``DistributedActorSystem/executeDistributedTarget(on:target:invocationDecoder:handler:)``.
586
+ ///
587
+ /// Inspect the ``errorCode`` for details about the underlying reason this error was thrown.
579
588
@available ( SwiftStdlib 5 . 7 , * )
580
589
public struct ExecuteDistributedTargetError : DistributedActorSystemError {
581
590
public let errorCode : ErrorCode
582
591
public let message : String
583
592
584
593
public enum ErrorCode {
585
- /// Thrown when unable to resolve the target identifier to a function accessor.
594
+ /// Unable to resolve the target identifier to a function accessor.
586
595
/// This can happen when the identifier is corrupt, illegal, or wrong in the
587
596
/// sense that the caller and callee do not have the called function recorded
588
597
/// using the same identifier.
589
598
case targetAccessorNotFound
590
599
591
- /// A general issue during the execution of the distributed call target ocurred.
600
+ /// Call target has different number of parameters than arguments
601
+ /// provided by the invocation decoder.
602
+ case invalidParameterCount
603
+
604
+ /// Target expects generic environment information, but invocation decoder
605
+ /// provided no generic substitutions.
606
+ case missingGenericSubstitutions
607
+
608
+ /// Generic substitutions provided by invocation decoder are incompatible
609
+ /// with target of the call. E.g. the generic requirements on the actual
610
+ /// target could not be fulfilled by the obtained generic substitutions.
611
+ case invalidGenericSubstitutions
612
+
613
+ // Failed to deserialize type or obtain type information for call.
614
+ case typeDeserializationFailure
615
+
616
+ /// A general issue during the execution of the distributed call target occurred.
592
617
case other
593
618
}
594
619
0 commit comments