Skip to content

Commit 371b24a

Browse files
hyochanclaude
andcommitted
fix: address CodeRabbit review issues for Billing Programs API
- Add error logging and status messages to empty catch blocks in AlternativeBillingScreen.kt - Fix exception propagation in OpenIapModule.kt Proxy handler using resumeWithException() - Add null-safe activity handling to prevent potential NPE 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ca306c7 commit 371b24a

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

packages/google/Example/src/main/java/dev/hyo/martie/screens/AlternativeBillingScreen.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,17 @@ fun AlternativeBillingScreen(navController: NavController) {
638638
}
639639

640640
// Step 2: Launch external link
641+
val currentActivity = activity
642+
if (currentActivity == null) {
643+
iapStore.postStatusMessage(
644+
"Activity not available",
645+
PurchaseResultStatus.Error
646+
)
647+
return@launch
648+
}
649+
641650
val launched = iapStore.launchExternalLink(
642-
activity!!,
651+
currentActivity,
643652
LaunchExternalLinkParamsAndroid(
644653
billingProgram = selectedBillingProgram,
645654
launchMode = ExternalLinkLaunchModeAndroid.LaunchInExternalBrowserOrApp,
@@ -745,7 +754,11 @@ fun AlternativeBillingScreen(navController: NavController) {
745754
)
746755
}
747756
} catch (e: Exception) {
748-
// Error handled by store
757+
android.util.Log.e("AlternativeBilling", "Legacy alternative billing error: ${e.message}", e)
758+
iapStore.postStatusMessage(
759+
"Alternative billing failed: ${e.message}",
760+
PurchaseResultStatus.Error
761+
)
749762
}
750763
}
751764
},
@@ -791,7 +804,11 @@ fun AlternativeBillingScreen(navController: NavController) {
791804
// If user selects Google Play → onPurchaseUpdated callback
792805
// If user selects alternative → UserChoiceBillingListener callback
793806
} catch (e: Exception) {
794-
// Error handled by store
807+
android.util.Log.e("AlternativeBilling", "User choice billing error: ${e.message}", e)
808+
iapStore.postStatusMessage(
809+
"User choice billing failed: ${e.message}",
810+
PurchaseResultStatus.Error
811+
)
795812
}
796813
}
797814
},

packages/google/openiap/src/play/java/dev/hyo/openiap/OpenIapModule.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import kotlinx.coroutines.Dispatchers
6868
import kotlinx.coroutines.suspendCancellableCoroutine
6969
import kotlinx.coroutines.withContext
7070
import kotlin.coroutines.resume
71+
import kotlin.coroutines.resumeWithException
7172
import java.lang.ref.WeakReference
7273

7374
// AlternativeBillingMode moved to main source set (shared between Play and Horizon)
@@ -515,15 +516,15 @@ class OpenIapModule(
515516
externalTransactionToken = token
516517
))
517518
} else if (continuation.isActive) {
518-
throw OpenIapError.PurchaseFailed
519+
continuation.resumeWithException(OpenIapError.PurchaseFailed)
519520
}
520521
} catch (e: Exception) {
521522
OpenIapLog.e("Failed to extract token: ${e.message}", e, TAG)
522-
if (continuation.isActive) throw OpenIapError.PurchaseFailed
523+
if (continuation.isActive) continuation.resumeWithException(OpenIapError.PurchaseFailed)
523524
}
524525
} else {
525526
OpenIapLog.e("Reporting details creation failed: ${result?.debugMessage}", tag = TAG)
526-
if (continuation.isActive) throw OpenIapError.PurchaseFailed
527+
if (continuation.isActive) continuation.resumeWithException(OpenIapError.PurchaseFailed)
527528
}
528529
}
529530
null

0 commit comments

Comments
 (0)