Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-502

Reimplement errors as structs



    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 1.0.0-rc0
    • None


      Edit: See design in WRITING-4592

      The discussions in the rust driver error API reviews made me realize that our error cases are extremely rigid. For example, if we wanted to add a new field to a specific case (e.g. "errorLabels" if they weren't already), it would be a breaking change since all the pattern matching users are doing would need to be updated. In general, additive changes aren't breaking, and the specs operate under this assumption (as evidenced by errorLabels). 

      To solve this, we could move the fields on the enum into a struct embedded in each of the cases (e.g. .writeError(WriteFailure)) or make the errors themselves be defined as structs. Originally, I defined all the errors as enums since I think that is generally the default way errors are defined, but it is still acceptable to define them as either structs or classes if they're more complicated. We can avoid classes though since we have no intention of doing any inheritance or have need for them to be reference types.

      We should consider re-defining the errors in such a way that we can add new fields in the future without major version upgrades and whether doing so would have an adverse effect on the API.

      some relevant reading:




            patrick.freed@mongodb.com Patrick Freed
            patrick.freed@mongodb.com Patrick Freed
            0 Vote for this issue
            1 Start watching this issue