Resolution: Won't Do
Docs for JSONEncoder.encode() state:
- The value fails to encode, or contains a nested value that fails to encode—this method throws the corresponding error.
Yet the actual implementation appears to do something more like
i.e., a preconditionFailure.
Testing the following in a playground
let encodable = [NSError(domain: "domain", code: *100*, userInfo: *nil*)]
we see that, unlike the promised throw, execution halts with a fatal error.
This is contrary to desirable function, in that there is no way to determine whether, for example, an Array (which claims conformance with Encodable and therefore can't be skipped via a guard) will successfully encode or simply crash.
Ideally, this is exactly the purpose of try, which should allow us to get a result or not if none can be had.