Skip to content

Bridge FirebaseFunctionsException to an iOS-shaped NSError - #95

Merged
marcprux merged 1 commit into
skiptools:mainfrom
vincentborko:functions-nserror-bridge
Jul 18, 2026
Merged

Bridge FirebaseFunctionsException to an iOS-shaped NSError#95
marcprux merged 1 commit into
skiptools:mainfrom
vincentborko:functions-nserror-bridge

Conversation

@vincentborko

Copy link
Copy Markdown
Contributor

On Android, Cloud Functions failures are wrapped in a generic ErrorException with no domain or code, so consumers can't classify them the way they can on iOS (FIRFunctionsErrorDomain + gRPC status codes) — or the way this wrapper already bridges Firestore (FIRFirestoreErrorDomain).

This mirrors the existing asNSError(firestoreException:) for Functions:

  • FunctionsErrorDomain = "com.firebase.functions" (matches iOS)
  • FunctionsErrorCode enum — canonical gRPC codes 0–16 (same numbering as FirestoreErrorCode and iOS FunctionsErrorCode)
  • asNSError(functionsException:) — maps the exception. Firestore's Code exposes value(); the Functions Code does not, but the enum is declared in gRPC order, so its ordinal equals the code value.

Both call() overloads (async + completion) now surface the mapped NSError instead of the opaque wrapper, letting callers detect e.g. unavailable(14) / deadlineExceeded(4) and treat a Functions timeout / backend-unreachable as expected connectivity rather than an actionable error.

Verified building green in a consuming Skip app (Android assembleDebug): libSkipFirebaseFunctions.so rebuilds with the bridge and a downstream domain/code classifier compiles against it on Android + iOS.

Cloud Functions failures on Android were wrapped in a generic ErrorException
with no domain/code, so callers could not classify them the way they can on
iOS (FIRFunctionsErrorDomain + gRPC status codes) or the way Firestore already
does here (FIRFirestoreErrorDomain).

Mirror the Firestore pattern: add FunctionsErrorDomain ("com.firebase.functions",
matching iOS), a FunctionsErrorCode enum (canonical gRPC codes 0–16), and
asNSError(functionsException:). Both call() overloads now surface the mapped
NSError. The Android Code enum is declared in gRPC order, so its `ordinal` is
the code value (Firestore's Code exposes value(); Functions' does not).

Lets consumers detect e.g. unavailable(14)/deadlineExceeded(4) to treat a
Functions timeout / backend-unreachable as expected connectivity rather than
an actionable error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EncjCGPMYW8P7TDqgoJpmD
@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2026
@marcprux
marcprux merged commit ed0f0e5 into skiptools:main Jul 18, 2026
2 checks passed
@marcprux

Copy link
Copy Markdown
Member

Very nice, thanks!

marcprux pushed a commit that referenced this pull request Jul 25, 2026
Android auth failures reached Swift as a bare `ErrorException`. Its
`localizedDescription` is the generic bridge text ("The operation could not
be completed. (SwiftJNI.ThrowableError error 1.)"), so a caller could not
tell "wrong password" from "email already in use" — and any message it
derived from the error was wrong. On iOS the same failures carry
`FIRAuthErrorDomain` plus a `FIRAuthErrorCode`, which is what cross-platform
callers key off.

`mapAuthNSError` now resolves `FirebaseAuthException.getErrorCode()` to the
matching `FIRAuthErrorCode` raw value and keeps the Android message in
`NSLocalizedDescriptionKey`, with a fallback on the exception class for
unknown codes. `FirebaseNetworkException` (not a FirebaseAuthException, no
error code) maps to `.networkError`. `AuthErrorCode` grows from one case to
the resolvable set.

The mapping was previously only applied on the completion-handler paths; the
`async throws` ones threw straight through. signIn(withEmail:),
createUser(withEmail:), sendPasswordReset(withEmail:),
User.sendEmailVerification(), User.reauthenticate(with:) and User.delete()
now go through it too.

Mirrors `asNSError(functionsException:)` in SkipFirebaseFunctions (#95) and
`asNSError(firestoreException:)` in SkipFirebaseFirestore.


Claude-Session: https://claude.ai/code/session_01MxxbQFDQyDkNvFMZaV5Aij

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants