Skip to content

Commit

Permalink
propagate error code in case of client reset errors in the callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-cab committed Nov 17, 2023
1 parent b0b4936 commit 4011f5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/realm/object-store/c_api/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ RLM_API void realm_config_set_should_compact_on_launch_function(realm_config_t*
{
if (func) {
auto should_func = [=](uint64_t total_bytes, uint64_t used_bytes) -> bool {
auto result = func(userdata, total_bytes, used_bytes);
if (auto usercode_error = ErrorStorage::get_thread_local()->get_and_clear_usercode_error())
throw CallbackFailed{usercode_error};
return result;
if (!func(userdata, total_bytes, used_bytes)) {
throw CallbackFailed{ErrorStorage::get_thread_local()->get_and_clear_usercode_error()};
return false;
}
return true;
};
config->should_compact_on_launch_function = std::move(should_func);
}
Expand Down
4 changes: 2 additions & 2 deletions src/realm/object-store/c_api/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ RLM_API void realm_sync_config_set_before_client_reset_handler(realm_sync_config
auto cb = [callback, userdata = SharedUserdata(userdata, FreeUserdata(userdata_free))](SharedRealm before_realm) {
realm_t r1{before_realm};
if (!callback(userdata.get(), &r1)) {
throw CallbackFailed();
throw CallbackFailed{ErrorStorage::get_thread_local()->get_and_clear_usercode_error()};
}
};
config->notify_before_client_reset = std::move(cb);
Expand All @@ -404,7 +404,7 @@ RLM_API void realm_sync_config_set_after_client_reset_handler(realm_sync_config_
realm_t r1{before_realm};
auto tsr = realm_t::thread_safe_reference(std::move(after_realm));
if (!callback(userdata.get(), &r1, &tsr, did_recover)) {
throw CallbackFailed();
throw CallbackFailed{ErrorStorage::get_thread_local()->get_and_clear_usercode_error()};
}
};
config->notify_after_client_reset = std::move(cb);
Expand Down

0 comments on commit 4011f5f

Please sign in to comment.