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

Reimplement errors as structs

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0-rc0
    • Component/s: None
    • Labels:

      Description

      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:

        Attachments

          Activity

            People

            Assignee:
            patrick.freed Patrick Freed
            Reporter:
            patrick.freed Patrick Freed
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: