firebase-unity-sdk
firebase-unity-sdk copied to clipboard
[Bug] Unity Firebase Functions error codes different on iOS than Android
[REQUIRED] Please fill in the following fields:
- Unity editor version: 2021.2.15f1
- Firebase Unity SDK version: 9.0.0
- Source you installed the SDK: (.unitypackage or Unity Package Manager)](https://firebase.google.com/download/unity)
- Problematic Firebase Component: Functions
- Other Firebase Components in use: Auth, Database, Storage, Crashlytics, Remote Config.
- Additional SDKs you are using: Infinity Maps, Easy Mobile (2.17.4)
- Platform you are using the Unity editor on: Mac.S
- Platform you are targeting: iOS, Android,
- Scripting Runtime: IL2CPP
- Pre-built SDK from the website
[REQUIRED] Please describe the issue here:
Since upgrading from Firebase 7.2.0 to 9.0.0 we have found that Function errors are no longer working as expected on iOS. Specifically we have a Firebase function that normally returns an error code of "notfound" after we cast the Task error as:
FunctionsException fbEx = task.Exception.InnerException.GetBaseException() as FunctionsException;
This was returning "notfound" on iOS before the 9.0.0 upgrade but now returns "internal", Android continues to return the expected error code.
(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)
Steps to reproduce:
Build a project using Firebase 7.2.0 and invoke a function that would be expected to return the error code "notfound" and observe the result occurring on Android and iOS devices. Upgrade to Firebase Unity SDK 9.0.0 and observe that iOS now only returns the error "internal" where once it return "notfound".
Additional: After further testing we compared iOS and Android errors buy forcing errors with known return types, We have a cloud function that returns "Already Exists" when trying to redeem a code, Android returns the formatted error message in the .message property and has an error code of "alreadyexists". On iOS we get the correct .message but we get the error code "notfound". Further to this we have another cloud function that should return "Not Found" when using another code, Android shows the correct .message and .errorcode in the returned error, but iOS returns "One or more errors occurred (INTERNAL)" and the error code "internal".
This testing seem to show error codes for iOS are a bit random, [EDIT] FunctionsException issues we faced were due to a nested Task, the Firebase functions do return FunctionsExceptions.
Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? No, not had time yet.
What happened? How can we make the problem occur? This could be a description, log/console output, etc.
If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.
Relevant Code:
// TODO(you): code here to reproduce the problem
Hi @steve6t6,
Thanks for reporting this issue. In order to identify what's causing this, could you provide the error logs seen from the console along with the code that returns said error?
Hello @paulinon
Our Function code is all wrapped up in an adaptor, with retry behaviours, but the gist is this. Function Invokation:
var function = functions.GetHttpsCallable(_method);
Assert.IsNotNull(function, $"Firebase function failure: {{{_method}}}");
return function.CallAsync(_data).ContinueWith((task) =>
{
if(task.IsFaulted) {
FunctionsException _fEx = task.Exception.InnerException as FunctionsException;
if(_fEx != null) {
Debug.LogError($"Internal exception code {_fEx.ErrorCode}"); }
Debug.LogError($"Cloud function task failed, this should pass up the task error");
PrintFunctionError(task.Exception); }}
The print function error function
private void PrintFunctionError(AggregateException Exception) {
// https://firebase.google.com/docs/functions/callable
foreach (var inner in Exception.InnerExceptions) {
if (inner is FunctionsException) {
Debug.LogError($"Inner exception is of type FunctionsException");
var e = (FunctionsException) inner;
// Function error code, will be INTERNAL if the failure
// was not handled properly in the function call.
var code = e.ErrorCode;
var message = e.Message;
Debug.LogError($"Error loop: Code: [{code}], Message: [{message}]"); }
else{
Debug.LogError($"Inner exception is not of type FunctionsException, inner message: {inner.Message}"); }}}
The output from this code on iOS is:
Internal exception code Internal Cloud function task failed, this should pass up the task error Inner exception is of type FunctionsException Error loop: Code: [Internal], Message [INTERNAL]
The output on Android is:
Internal exception code NotFound Cloud function task failed, this should pass up the task error Inner exception is of type FunctionsException Error loop: Code: [NotFound], Message [Voucher: exampleVoucher not found]
The server side function definition is:
index.ts
import * as admin from 'firebase-admin';
admin.initializeApp();
export const ThrowNotFound = functions.https.onCall(async (data, context) => {
// * Validate User
throw new HttpsError('not-found', 'This should be a NOT_FOUND error');
});
export const ThrowAlreadyExists = functions.https.onCall(async (data, context) => {
// * Validate User
throw new HttpsError('already-exists', 'This should be an ALREADY_EXISTS error');
});
[EDIT] the server console error is:
11:39:43.367 am VoucherRedeem > Function execution took 71 ms. Finished with status code: 404
Hey @steve6t6. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Hello. We have built a cut down version of the project, we have imported all our firebase dependancies and published two functions to our console. The functions are the ones defined above.
We built a simple unity project, each function gets its own button and feedback text. On iOS both functions return the wrong error codes. In the Unity editor & Android, both buttons return the expected error codes.
I can upload the project (Unity and Firebase) to GitHub if you can provide me the details of someone to share the repo with. (For security)
iOS: function "ThrowAlreadyExists" returns NotFound. (Incorrect) iOS: function "ThrowNotFound" returns Internal. (Incorrect) Android: function "ThrowAlreadyExists" returns AlreadyExists. Android: function "ThrowNotFound" returns NotFound. Unity Editor: function "ThrowAlreadyExists" returns AlreadyExists. Unity Editor: function "ThrowNotFound" returns NotFound.
Hi @steve6t6,
You may invite me as a collaborator when uploading your project to GitHub. Make sure that it's free from personally identifiable information. Alternatively, you may add your project to Google Drive and share it with [email protected]
.
I look forward to hearing from you soon.
Hi @steve6t6,
You may invite me as a collaborator when uploading your project to GitHub. Make sure that it's free from personally identifiable information. Alternatively, you may add your project to Google Drive and share it with
[email protected]
.I look forward to hearing from you soon.
We have uploaded the repository and added you. Thanks in advance for your time.
Hi @steve6t6,
I was able to replicate the issue using the sample project you provided. It's rather odd that upgrading the SDK resulted to a different error message in a specific platform. I've observed this behavior in the latest SDK version (9.1.0) as well.
I'll be relaying my observations to the team. In the meantime, I'll be marking this as a bug for now.
Hello @paulinon , any news on this issue?
Any further update on this? We're unable to respond appropriately to errors as we cannot trust that the error codes being returned are correct. Is this fixed in a newer version?
Is this bug being addressed? is there a duplicate thread?