Repository navigation
fix(cloud_functions): surface httpsCallable stream errors as FirebaseFunctionsException #18834
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
837f6d4
fix(cloud_functions): surface httpsCallable stream errors as Firebase…
Lyokone fdb1848
Merge branch 'main' of https://github.com/firebase/flutterfire into f…
Lyokone 0e9d065
fix(cloud_functions): report the real code for stream errors on iOS a…
Lyokone c10dc15
fix(cloud_functions,android): report the code and message the functio…
Lyokone ac79230
fix(cloud_functions,android): don't crash when a stream fails while r…
Lyokone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
...ns/android/src/test/java/io/flutter/plugins/firebase/functions/TestFirebaseFunctions.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright 2026 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
| package io.flutter.plugins.firebase.functions; | ||
|
|
||
| import android.content.ContextWrapper; | ||
| import com.google.android.gms.tasks.Tasks; | ||
| import com.google.firebase.functions.FirebaseFunctions; | ||
|
|
||
| /** | ||
| * Creates a {@link FirebaseFunctions} for tests that never reach the network. Its constructor is | ||
| * Kotlin {@code internal}, so Kotlin code outside the SDK cannot call it, but Java can. | ||
| */ | ||
| final class TestFirebaseFunctions { | ||
| private TestFirebaseFunctions() {} | ||
|
|
||
| static FirebaseFunctions create() { | ||
| return new FirebaseFunctions( | ||
| new ContextWrapper(null), | ||
| "test-project", | ||
| "us-central1", | ||
| limitedUseAppCheckTokens -> Tasks.forResult(null), | ||
| Runnable::run, | ||
| // Drops the security provider install, which needs a device. | ||
| command -> {}); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
.../android/src/test/java/io/flutter/plugins/firebase/functions/TestFunctionsExceptions.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2026 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
| package io.flutter.plugins.firebase.functions; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
| import com.google.firebase.functions.FirebaseFunctionsException; | ||
|
|
||
| /** | ||
| * Creates {@link FirebaseFunctionsException}s for tests. Its constructors are Kotlin {@code | ||
| * internal}, so Kotlin code outside the SDK cannot call them, but Java can. | ||
| */ | ||
| final class TestFunctionsExceptions { | ||
| private TestFunctionsExceptions() {} | ||
|
|
||
| static FirebaseFunctionsException create( | ||
| String message, | ||
| FirebaseFunctionsException.Code code, | ||
| @Nullable Object details, | ||
| @Nullable Throwable cause) { | ||
| // The four-argument constructor rejects a null cause. | ||
| return cause == null | ||
| ? new FirebaseFunctionsException(message, code, details) | ||
| : new FirebaseFunctionsException(message, code, details, cause); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...c/test/kotlin/io/flutter/plugins/firebase/functions/FirebaseFunctionsStreamHandlerTest.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright 2026 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
| package io.flutter.plugins.firebase.functions | ||
|
|
||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.junit.runners.JUnit4 | ||
|
|
||
| @RunWith(JUnit4::class) | ||
| class FirebaseFunctionsStreamHandlerTest { | ||
| private val eventSink = RecordingEventSink() | ||
| private val handler = FirebaseFunctionsStreamHandler(TestFirebaseFunctions.create()) | ||
|
|
||
| // Sets neither functionName nor functionUri, so the stream fails before subscribing. | ||
| private val invalidArguments = mapOf("limitedUseAppCheckToken" to false) | ||
|
|
||
| @Test | ||
| fun onListen_setupFailureSendsErrorThenEndsStream() { | ||
| handler.onListen(invalidArguments, eventSink) | ||
|
|
||
| val message = "Either functionName or functionUri must be set" | ||
| assertEquals( | ||
| listOf( | ||
| listOf( | ||
| "error", | ||
| "firebase_functions", | ||
| message, | ||
| mapOf("code" to "unknown", "message" to message)), | ||
| listOf("endOfStream")), | ||
| eventSink.events) | ||
| } | ||
|
|
||
| @Test | ||
| fun onCancel_afterSetupFailureDoesNotThrow() { | ||
| handler.onListen(invalidArguments, eventSink) | ||
|
|
||
| handler.onCancel(invalidArguments) | ||
| } | ||
| } |
This file contains hidden or 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
29 changes: 29 additions & 0 deletions
29
...tions/android/src/test/kotlin/io/flutter/plugins/firebase/functions/RecordingEventSink.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2026 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
| package io.flutter.plugins.firebase.functions | ||
|
|
||
| import io.flutter.plugin.common.EventChannel.EventSink | ||
| import io.flutter.plugin.common.StandardMethodCodec | ||
|
|
||
| /** | ||
| * Records the events sent to it, in order. Encodes them first, as EventChannel does, so a value the | ||
| * codec can't send fails the test instead of crashing the app. | ||
| */ | ||
| class RecordingEventSink : EventSink { | ||
| val events = mutableListOf<List<Any?>>() | ||
|
|
||
| override fun success(event: Any?) { | ||
| StandardMethodCodec.INSTANCE.encodeSuccessEnvelope(event) | ||
| events.add(listOf("success", event)) | ||
| } | ||
|
|
||
| override fun error(errorCode: String?, errorMessage: String?, errorDetails: Any?) { | ||
| StandardMethodCodec.INSTANCE.encodeErrorEnvelope(errorCode!!, errorMessage, errorDetails) | ||
| events.add(listOf("error", errorCode, errorMessage, errorDetails)) | ||
| } | ||
|
|
||
| override fun endOfStream() { | ||
| events.add(listOf("endOfStream")) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems android can report the function's real code.
PublisherStreamsets the code toINTERNAL, butdetailsis the decoded error{status, message, details}, and the exception message is that map'stoString(). InStreamResponseSubscriber.onError, parse it the wayFirebaseFunctionsException.fromResponsedoes:statusbecomes the code,messagebecomes the message, and only the innerdetailsis kept. Do this on the stream path only. An unknownstatusstaysinternal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c10dc15: on the stream path,
onErrornow reads the decoded error the wayfromResponsedoes.statusbecomes the code,messagethe message, and only the innerdetailsis kept. As infromResponse, an unknown status givesinternalwithout message or details. The e2e now expectsinvalid-argumenton Android too and passes on the emulator.While verifying it I found a crash on this branch, fixed in ac79230. When reading the stream fails after the response started (timeout, dropped connection, bad JSON),
PublisherStreampasses the error asdetails, and the codec threwUnsupported valueon the main thread. It now maps todeadline-exceeded/unavailablelike calls. Details are in the PR description.