I agree on the changes. In particular, it looks great to me that the Error
type parameters is constrained to conform to Swift.Error
, with self-conformance, and the Result
type has minimum APIs.
I want a guideline when to use the Result
type. Opinions seems divided even in the Core Team as follows.
If I correctly understood, it seems like @Joe_Groff suggests that JSONDecoder.decode(_:from:)
returns a Result
and @John_McCall does not. I think errors from JSONDecoder.decode(_:from:)
are something between simple domain errors and recoverable errors defined in "Error Handling Rationale and Proposal". Those errors are caused by some different conditions. nil
is obviously insufficient to represent those errors. Also they don't require manual propagations. However they are not "systemic errors", and throws/try
does not allow us to specify their error type (without typed throws). Should JSONDecoder.decode(_:from:)
return a Result
?