Skip to content

Commit 80dbf09

Browse files
committed
add operation checks to all executors
To ensure operations are not silently skipped each executor now checks if it can process all the operations. This is important since bugs can go unnoticed for a while and without this it's hard to debug too.
1 parent 7fe2010 commit 80dbf09

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/IdentityOperationExecutor.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ internal class IdentityOperationExecutor(
2626
override suspend fun execute(operations: List<Operation>): ExecutionResponse {
2727
Logging.debug("IdentityOperationExecutor(operations: $operations)")
2828

29+
if (operations.any { it !is SetAliasOperation && it !is DeleteAliasOperation }) {
30+
throw Exception("Unrecognized operation(s)! Attempted operations:\n$operations")
31+
}
32+
33+
if (operations.any { it is SetAliasOperation } &&
34+
operations.any { it is DeleteAliasOperation }
35+
) {
36+
throw Exception("Can't process SetAliasOperation and DeleteAliasOperation at the same time.")
37+
}
38+
2939
// An alias group is an appId/onesignalId/aliasLabel combo, so we only care
3040
// about the last operation in the group, as that will be the effective end
3141
// state to this specific alias for this user.

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/LoginUserFromSubscriptionOperationExecutor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ internal class LoginUserFromSubscriptionOperationExecutor(
2727
override suspend fun execute(operations: List<Operation>): ExecutionResponse {
2828
Logging.debug("LoginUserFromSubscriptionOperationExecutor(operation: $operations)")
2929

30+
if (operations.size > 1) {
31+
throw Exception("Only supports one operation! Attempted operations:\n$operations")
32+
}
33+
3034
val startingOp = operations.first()
3135

3236
if (startingOp is LoginUserFromSubscriptionOperation) {

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/LoginUserOperationExecutor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal class LoginUserOperationExecutor(
5555
val startingOp = operations.first()
5656

5757
if (startingOp is LoginUserOperation) {
58-
return loginUser(startingOp, operations)
58+
return loginUser(startingOp, operations.drop(1))
5959
}
6060

6161
throw Exception("Unrecognized operation: $startingOp")
@@ -153,6 +153,7 @@ internal class LoginUserOperationExecutor(
153153
is TransferSubscriptionOperation -> subscriptions = createSubscriptionsFromOperation(operation, subscriptions)
154154
is UpdateSubscriptionOperation -> subscriptions = createSubscriptionsFromOperation(operation, subscriptions)
155155
is DeleteSubscriptionOperation -> subscriptions = createSubscriptionsFromOperation(operation, subscriptions)
156+
else -> throw Exception("Unrecognized operation: $operation")
156157
}
157158
}
158159

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/RefreshUserOperationExecutor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ internal class RefreshUserOperationExecutor(
3838
override suspend fun execute(operations: List<Operation>): ExecutionResponse {
3939
Logging.log(LogLevel.DEBUG, "RefreshUserOperationExecutor(operation: $operations)")
4040

41+
if (operations.any { it !is RefreshUserOperation }) {
42+
throw Exception("Unrecognized operation(s)! Attempted operations:\n$operations")
43+
}
44+
4145
val startingOp = operations.first()
4246
if (startingOp is RefreshUserOperation) {
4347
return getUser(startingOp)

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/SubscriptionOperationExecutor.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ internal class SubscriptionOperationExecutor(
4949
return if (startingOp is CreateSubscriptionOperation) {
5050
createSubscription(startingOp, operations)
5151
} else if (operations.any { it is DeleteSubscriptionOperation }) {
52-
deleteSubscription(operations.first { it is DeleteSubscriptionOperation } as DeleteSubscriptionOperation)
52+
if (operations.size > 1) {
53+
throw Exception("Only supports one operation! Attempted operations:\n$operations")
54+
}
55+
val deleteSubOps = operations.filterIsInstance<DeleteSubscriptionOperation>()
56+
deleteSubscription(deleteSubOps.first())
5357
} else if (startingOp is UpdateSubscriptionOperation) {
5458
updateSubscription(startingOp, operations)
5559
} else if (startingOp is TransferSubscriptionOperation) {
60+
if (operations.size > 1) {
61+
throw Exception("TransferSubscriptionOperation only supports one operation! Attempted operations:\n$operations")
62+
}
5663
transferSubscription(startingOp)
5764
} else {
5865
throw Exception("Unrecognized operation: $startingOp")

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/UpdateUserOperationExecutor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ internal class UpdateUserOperationExecutor(
114114

115115
deltasObject = PropertiesDeltasObject(deltasObject.sessionTime, deltasObject.sessionCount, amountSpent, purchasesArray)
116116
}
117+
else -> throw Exception("Unrecognized operation: $operation")
117118
}
118119
}
119120

0 commit comments

Comments
 (0)