Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup error code types #62

Merged
merged 6 commits into from
Apr 8, 2024
Merged

Cleanup error code types #62

merged 6 commits into from
Apr 8, 2024

Conversation

darinf
Copy link

@darinf darinf commented Apr 6, 2024

Goals:

  • Allow consumers to cast Error instances received to AuthErrorCode or FirestoreErrorCode, corresponding to the API used.
  • Allow consumers to write code like AuthErrorCode.userDisabled.
  • Allow consumers to write code like AuthErrorCode(.userDisabled).
  • Make sure {Auth,Firestore}ErrorCode conform to RawRepresentable with a RawValue of type Int.

Also changes:

  • Removes FirebaseError now that it is no longer needed. This required changing resultAndError to be generic on the error type returned. This is necessary since the underlying C++ API does not have any type information for the error codes produced (they are just integers). At the Swift layer we want to generate the right concrete error types.

This is all intended for better conformance to how these types are reflected to Swift from Obj C.

Intentionally not trying to make these error types extend from NSError at this time. That may be interesting follow-up work.

Changes:
- Allow consumers to cast `Error` instances received to `AuthErrorCode`
  or `FirestoreErrorCode`, corresponding to the API used.
- Allow consumers to write code like `AuthErrorCode.userDisabled`.
- Allow consumers to write code like `AuthErrorCode(.userDisabled)`.
- Make sure `{Auth,Firestore}ErrorCode` conform to `RawRepresentable`
  with a `RawValue` of type `Int`.
- `FirebaseError` just becomes a protocol, and `resultAndError` becomes
  a generic function that takes an `ErrorType.Type` parameter. This is
  necessary since the underlying C++ API does not have any type
  information for the error codes produced (they are just integers). At
  the Swift layer we want to generate the right concrete error types.

This is all intended for better conformance to how these types are
reflected to Swift from Obj C.
@darinf darinf marked this pull request as ready for review April 6, 2024 01:13
Sources/FirebaseAuth/FirebaseAuthError.swift Outdated Show resolved Hide resolved
Sources/FirebaseCore/FirebaseError.swift Outdated Show resolved Hide resolved
Sources/FirebaseFirestore/FirestoreErrorCode.swift Outdated Show resolved Hide resolved
@darinf darinf requested a review from compnerd April 8, 2024 15:27
Sources/FirebaseAuth/FirebaseAuthError.swift Outdated Show resolved Hide resolved
Sources/FirebaseAuth/FirebaseAuthError.swift Outdated Show resolved Hide resolved
Sources/FirebaseAuth/FirebaseAuthError.swift Outdated Show resolved Hide resolved
Sources/FirebaseAuth/FirebaseAuthError.swift Show resolved Hide resolved
Sources/FirebaseCore/FutureProtocol.swift Outdated Show resolved Hide resolved
Sources/FirebaseCore/FutureProtocol.swift Outdated Show resolved Hide resolved
Sources/FirebaseFirestore/FirestoreErrorCode.swift Outdated Show resolved Hide resolved
Sources/FirebaseFirestore/FirestoreErrorCode.swift Outdated Show resolved Hide resolved
@compnerd compnerd dismissed their stale review April 8, 2024 20:53

Comments on newer revision

@darinf darinf requested a review from compnerd April 8, 2024 21:47
@darinf darinf merged commit d0f1b9f into main Apr 8, 2024
2 checks passed
@darinf darinf deleted the darin/auth-error-code branch April 8, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants