-
Notifications
You must be signed in to change notification settings - Fork 596
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
fix(functions): use notifyError() instead of throwing #6773
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
Generated by 🚫 Danger |
Coverage Report 1Affected ProductsTest Logs |
Size Report 1Affected Products
Test Logs |
rlazo
approved these changes
Mar 14, 2025
emilypgoogle
approved these changes
Mar 14, 2025
emilypgoogle
pushed a commit
that referenced
this pull request
Mar 17, 2025
Throwing inside the `PublisherStream` causes a Runtime exception that can't be caught in the call site. Instead, we should use `notifyError()` so that the error can be caught in the `Subscriber#onError()` function. I tried to catch the exception using both of the code snippets below, but none of them worked. (they both work with the changes in this PR): ```kotlin functions.getHttpsCallable("nonExistentFunction") .stream().asFlow() .catch { // Handle error for a 404 function } .collect { // ... } ``` ```kotlin try { functions.getHttpsCallable("nonExistentFunction") .stream().asFlow() .collect { // ... } } catch(e: Exception) { // Handle error for a 404 function } ``` Runtime exception thrown: ``` FATAL EXCEPTION: OkHttp Dispatcher Process: com.google.samples.quickstart.functions, PID: 13321 com.google.firebase.functions.FirebaseFunctionsException: Value <html><head> of type java.lang.String cannot be converted to JSONObject Unexpected Response: <html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>404 Page not found</title> </head> <body text=#000000 bgcolor=#ffffff> <h1>Error: Page not found</h1> <h2>The requested URL was not found on this server.</h2> <h2></h2> </body></html> at com.google.firebase.functions.PublisherStream.validateResponse(PublisherStream.kt:316) at com.google.firebase.functions.PublisherStream.access$validateResponse(PublisherStream.kt:41) at com.google.firebase.functions.PublisherStream$startStreaming$1$4.onResponse(PublisherStream.kt:161) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651) at java.lang.Thread.run(Thread.java:1119) ```
rlazo
added a commit
that referenced
this pull request
Mar 24, 2025
These improvements are both in the SDK itself, and in the code used for the actual functions running in the cloud during integration testing: A summary of the changes is: - [Backend functions] Update the dependencies and node runtime version - [Backend functions] Add logging in case the client does not support streaming - [SDK] Use a more robust handle of the media type - [SDK] Fix issue introduced in #6773 that missed a return in case of error - [SDK] Other minor code fixes b/404814020
gubatron
pushed a commit
to gubatron/firebase-android-sdk
that referenced
this pull request
Mar 24, 2025
Throwing inside the `PublisherStream` causes a Runtime exception that can't be caught in the call site. Instead, we should use `notifyError()` so that the error can be caught in the `Subscriber#onError()` function. I tried to catch the exception using both of the code snippets below, but none of them worked. (they both work with the changes in this PR): ```kotlin functions.getHttpsCallable("nonExistentFunction") .stream().asFlow() .catch { // Handle error for a 404 function } .collect { // ... } ``` ```kotlin try { functions.getHttpsCallable("nonExistentFunction") .stream().asFlow() .collect { // ... } } catch(e: Exception) { // Handle error for a 404 function } ``` Runtime exception thrown: ``` FATAL EXCEPTION: OkHttp Dispatcher Process: com.google.samples.quickstart.functions, PID: 13321 com.google.firebase.functions.FirebaseFunctionsException: Value <html><head> of type java.lang.String cannot be converted to JSONObject Unexpected Response: <html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>404 Page not found</title> </head> <body text=#000000 bgcolor=#ffffff> <h1>Error: Page not found</h1> <h2>The requested URL was not found on this server.</h2> <h2></h2> </body></html> at com.google.firebase.functions.PublisherStream.validateResponse(PublisherStream.kt:316) at com.google.firebase.functions.PublisherStream.access$validateResponse(PublisherStream.kt:41) at com.google.firebase.functions.PublisherStream$startStreaming$1$4.onResponse(PublisherStream.kt:161) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651) at java.lang.Thread.run(Thread.java:1119) ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Throwing inside the
PublisherStream
causes a Runtime exception that can't be caught in the call site.Instead, we should use
notifyError()
so that the error can be caught in theSubscriber#onError()
function.I tried to catch the exception using both of the code snippets below, but none of them worked. (they both work with the changes in this PR):
Runtime exception thrown: