-
-
Notifications
You must be signed in to change notification settings - Fork 619
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
ensureConnection - fixed rejection handling #2316
ensureConnection - fixed rejection handling #2316
Conversation
@Mkolakoglu Can you please add a unit test for the case you are trying to fix? It's not clear to me what this is trying to solve |
Please note that there's coverage on that method. So, it failing must be captured by the Unit Tests. Thank you for your contribution |
Log.i(TAG, "Incorrect parameter in resolve") | ||
} | ||
}, | ||
{ | ||
if (it.size > 1 && it[0] is String && it[1] is String) { |
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.
it[0] as String, | ||
it[1] as String | ||
errorCode, | ||
errorMessage | ||
) | ||
} else { |
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.
In this block, Promise is not neither rejected nor resolved. So, when this block is called, any RNIap function is awaiting infitinitely. We have to reject the promise in this case
var errorCode: String? = null | ||
var errorMessage: String? = null | ||
if (it.isNotEmpty() && it[0] is WritableNativeMap) { | ||
val errorMap = it[0] as WritableNativeMap |
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.
Parsing code
and message
fields from it[0]
. So that, we can use them in promise.safeReject()
.
@@ -69,16 +69,26 @@ class RNIapModule( | |||
promise.safeReject(PromiseUtils.E_NOT_PREPARED, "Unable to auto-initialize connection") | |||
} | |||
} else { |
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.
Hi @andresesfm, sorry I can not do that atm because I am super busy atm. I can not even build the project on my machine and it will probably take some to fix the issues. Instead, I added comments on some lines, hope it makes more clear it for you. |
@Mkolakoglu thank you for the comments. I'm not understanding the edge case that makes you believe there's an issue. I have the following tests that pass: https://github.com/dooboolab/react-native-iap/blob/12.8.5/android/src/testPlay/java/com/dooboolab/RNIap/RNIapModuleTest.kt#L102 that test the scenario that you describe. What am I missing? |
Please correct me if I am wrong. That test seems to be testing only Let me describe how to create a failure scenario for
So that, when
You will see that, |
@Mkolakoglu I ran the example of safeReject('Code1', 'Hello'). Here is the breakpoint: As you can see there are 2 elements in the array, the first one is the code and the second one is the message. I don't see under what circumstances this could be an ArrayMap. The only place where Sorry if I'm not understanding correctly. Are you thinking about adding a new rejection inside |
Could you please share the unit test you wrote to get that output? It has been a while since I developed in Kotlin and it will be a little time consuming for me to write a new unit test.
No, I don't mean that. I am saying that the current one is not properly handling the rejections 😂 Please see the output of the You will also see the same result if you would follow the reproducable steps I shared above. |
I was digging deeper and found that This is the As you can see, it's triggering the reject fn on this line: https://github.com/facebook/react-native/blob/91a3a548e237cf9991105d10e2457422874d1e60/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java#L168 Which is converting the error info to |
Kind reminder @andresesfm |
Thank you for the reminder. I haven't had a chance to recreate the unit test. I'll do it this week |
@Mkolakoglu can you please take a look at the merge conflicts. Let's get this merged |
@andresesfm Done ✅ |
Also keep the old check for completeness
I added the old check back as a fallback. if does not interfere with your change |
fix type
Hi, I was trying to create a scenario that we can not establish BillingClient connection. To do that, I simply changed
initConnection
as below:After observing that scenario, I noticed that
ensureConnection
is not parsing the rejection parameters properly and it's only logging this info in the logcat, which is quite dangerous because it's happening silently and probably none of us is aware of this issue so far.When it's rejected, there is only 1 item in
it
array and here is the output ofit[0]
:I tried to fix the parameter handling and rejected the case when the parameters are incorrect instead of just logging it. So that, we will be aware of if anything goes wrong.