-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Cloud blocking functions errors are not handled properly #14052
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
@amirandalibi Thanks for sharing the issue and analysis. Your analysis sounds good to me and we would appreciate a pull request including a unit test that demonstrates the issue and fix. Also, my preference would be to use Swift Regular Expression syntax instead of |
Is there any update on this? It's pretty crucial functionality |
We haven't yet been able to prioritize in on the core team. In the meantime, we're open to a PR. See the discussion above. |
Hi @paulb777 is this going to be worked on at all? We updated our project and found the problem so have reverted dependencies for now but it seems to be a very temporary fix. |
I'll put this on the list for our next release and try to get it in. |
Do you have a rough ETA for the next release? Months aways or weeks? |
@AronTMC Planning the week of January 14th |
There is now a fix available in #14280. I'd appreciate if anyone seeing the issue could confirm the fix it releases. |
Description
In my Swift app, errors returned from Firebase Blocking Functions are not properly handled, resulting in the following generic error message:
Blocking function
The blocking function is running on Node.js 20 using
beforeUserCreated
and throws an error in the following format:The expected raw error response from this blocking function should resemble:
The root cause stems from two issues in the Firebase iOS SDK that lead to an improperly formatted error.
In
AuthBackend.swift
, the SDK attempts to split the error message string by colons. The intent was to separate the initial part (shortErrorMessage) from the remaining part (serverDetailErrorMessage). However, splitting by:
inadvertently captures portions of the URL, resulting in a truncated message((HTTP request to http
, which breaks the error handling.Current code
firebase-ios-sdk/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift
Lines 315 to 318 in 32a6788
Suggested Fix
To address this, I propose updating the parsing logic to identify the first colon’s index and split the string at that point, preserving the intended structure:
In
AuthErrorUtils.swift
, theblockingCloudFunctionServerResponse
function relies on replacing a hardcoded string to extract JSON data from the error. This dependency fails because the string"HTTP Cloud Function returned an error:"
is absent, leading to a JSON serialization error.Current code
firebase-ios-sdk/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift
Lines 509 to 528 in 32a6788
Suggested Fix
To avoid hardcoded string dependencies, I suggest using regex to directly capture the JSON object within the error string, making the SDK more resilient to changes. Here is the updated function:
With this fix, the Blocking Function error should be correctly handled, producing a clear and actionable message:
As recommended in the contribution guide, I wanted to share this approach before opening a pull request to gather any insights or feedback that could help further refine these fixes. Thank you for your time and consideration!
Reproducing the issue
step 1: throw a
httpsError
in yourbeforeUserCreated
Blocking Cloud Function (can be any blocking function)step 2: create a user in the swift app and catch the error, here's an example code
Firebase SDK Version
11.4.0
Xcode Version
Version 15.4 (15F31d)
Installation Method
Swift Package Manager
Firebase Product(s)
Authentication, Functions
Targeted Platforms
iOS
Relevant Log Output
No response
If using Swift Package Manager, the project's Package.resolved
No response
If using CocoaPods, the project's Podfile.lock
No response
The text was updated successfully, but these errors were encountered: