PKPaymentAuthorizationResult errors that are of Swift.Error type will crash the host application

Originator:peter.n.goldsmith
Number:rdar://35131271 Date Originated:23/10/2017
Status:Open Resolved:
Product:iOS Product Version:11
Classification:Crash Reproducible:Always
 
Area:
PassKit

Summary:
By providing any Swift error type in the array of errors for PKPaymentAuthorizationResult, will result in a crash

Steps to Reproduce:

https://gist.github.com/raven/85686d11b934a5fd34255ad73a29d912

Populate the errors array for an PKPaymentAuthorizationResult instance with a Swift error ie
```
struct DummyError: Error {}
```
Then pass this to the completion handler for `didAuthorizePayment`

Expected Results:
Payment sheet presents generic error

Actual Results:
App crashes with:
```
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '_SwiftValue').'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001134c61cb __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000010fb3ff41 objc_exception_throw + 48
	2   CoreFoundation                      0x000000011353ab95 +[NSException raise:format:] + 197
	3   Foundation                          0x000000010f544ada -[NSXPCEncoder _checkObject:] + 326
	4   Foundation                          0x000000010f777eee -[NSXPCEncoder _encodeUnkeyedObject:] + 49
	5   Foundation                          0x000000010f54d9e3 -[NSXPCEncoder _encodeArrayOfObjects:forKey:] + 221
	6   Foundation                          0x000000010f545132 -[NSXPCEncoder _encodeObject:] + 578
	7   PassKitCore                         0x00000001150f28e4 -[PKPaymentAuthorizationResult encodeWithCoder:] + 104
	8   Foundation                          0x000000010f545132 -[NSXPCEncoder _encodeObject:] + 578
	9   Foundation                          0x000000010f6c8afb _NSXPCSerializationAddInvocationWithOnlyObjectArgumentsArray + 139
	10  Foundation                          0x000000010f778279 -[NSXPCEncoder _encodeInvocationObjectArgumentsOnly:count:typeString:selector:isReply:into:] + 199
	11  Foundation                          0x000000010f776598 -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 3155
	12  Foundation                          0x000000010f7756c7 -[NSXPCConnection _sendSelector:withProxy:arg1:] + 100
...
```

Version/Build:
iOS 11

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!