Skip to content

Commit

Permalink
refactor: make the code parameter of safeReject non-nullable
Browse files Browse the repository at this point in the history
The reject method of Promise class became non-nullable in React Native 0.76 after rewriting it from Java to Kotlin. We fixed it being called with a nullable value in #2872 by providing and empty string as a fallback if it happens to be null. But after more investigation it seems like it's not called with a value that could be null anywhere in the code, so a better solution would be to just update the type of the `code` parameter to be non-nullable.
  • Loading branch information
mlazari committed Nov 1, 2024
1 parent 6a8756e commit 076b729
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/com/dooboolab/rniap/PromiseUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object PromiseUtils {

fun rejectPromisesForKey(
key: String,
code: String?,
code: String,
message: String?,
err: Exception?,
) {
Expand Down
8 changes: 4 additions & 4 deletions android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ fun Promise.safeResolve(value: Any?) {
fun Promise.safeReject(message: String) = this.safeReject(message, null, null)

fun Promise.safeReject(
code: String?,
code: String,
message: String?,
) = this.safeReject(code, message, null)

fun Promise.safeReject(
code: String?,
code: String,
throwable: Throwable?,
) = this.safeReject(code, null, throwable)

fun Promise.safeReject(
code: String?,
code: String,
message: String?,
throwable: Throwable?,
) {
try {
this.reject(code ?: "", message, throwable)
this.reject(code, message, throwable)
} catch (oce: ObjectAlreadyConsumedException) {
Log.d(TAG, "Already consumed ${oce.message}")
}
Expand Down

0 comments on commit 076b729

Please sign in to comment.