-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework sync exceptions based on new error codes.
- Loading branch information
Christian Melchior
committed
Aug 23, 2023
1 parent
e7b3c9e
commit 0c6a6af
Showing
31 changed files
with
424 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/CoreError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.realm.kotlin.internal.interop | ||
|
||
/** | ||
* Wrapper for C-API `realm_error_t`. | ||
* See https://github.com/realm/realm-core/blob/master/src/realm.h#L231 | ||
*/ | ||
class CoreError( | ||
categoriesNativeValue: Int, | ||
val errorCodeNativeValue: Int, | ||
messageNativeValue: String?, | ||
path: String, | ||
userError: Throwable? | ||
) { | ||
val categories: CategoryFlags = CategoryFlags((categoriesNativeValue)) | ||
val errorCode: ErrorCode? = ErrorCode.of(errorCodeNativeValue) | ||
val message = messageNativeValue | ||
val realmPath: String = path | ||
val userError: Throwable? = userError | ||
|
||
operator fun contains(category: ErrorCategory): Boolean = category in categories | ||
} | ||
|
||
data class CategoryFlags(val categoryFlags: Int) { | ||
|
||
companion object { | ||
/** | ||
* See error code mapping to categories here: | ||
* https://github.com/realm/realm-core/blob/master/src/realm/error_codes.cpp#L29 | ||
* | ||
* In most cases, only 1 category is assigned, but some errors have multiple. So instead of | ||
* overwhelming the user with many categories, we only select the most important to show | ||
* in the error message. "important" is of course tricky to define, but generally | ||
* we consider vague categories like [ErrorCategory.RLM_ERR_CAT_RUNTIME] as less important | ||
* than more specific ones like [ErrorCategory.RLM_ERR_CAT_JSON_ERROR]. | ||
* | ||
* In the current implementation, categories between index 0 and 7 are considered equal | ||
* and the order is somewhat arbitrary. No error codes has multiple of these categories | ||
* associated either. | ||
*/ | ||
val CATEGORY_ORDER: List<ErrorCategory> = listOf( | ||
ErrorCategory.RLM_ERR_CAT_CUSTOM_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_WEBSOCKET_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_SERVICE_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_JSON_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_CLIENT_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_SYSTEM_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_FILE_ACCESS, | ||
ErrorCategory.RLM_ERR_CAT_HTTP_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_INVALID_ARG, | ||
ErrorCategory.RLM_ERR_CAT_APP_ERROR, | ||
ErrorCategory.RLM_ERR_CAT_LOGIC, | ||
ErrorCategory.RLM_ERR_CAT_RUNTIME, | ||
) | ||
} | ||
|
||
/** | ||
* Returns a description of the most important category defined in [categoryFlags]. | ||
* If no known categories are found, "Unknown[categoryFlags]" is returned. | ||
*/ | ||
val description: String = CATEGORY_ORDER.firstOrNull { category -> | ||
category in this | ||
}?.description ?: "$categoryFlags" | ||
|
||
/** | ||
* Check whether a given [ErrorCategory] is included in the [categoryFlags]. | ||
*/ | ||
operator fun contains(category: ErrorCategory): Boolean = (categoryFlags and category.nativeValue) != 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.