From db944d2427a2c69121bfbdecf9020cde678613d5 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Mon, 12 Aug 2024 15:55:42 -0400 Subject: [PATCH 1/4] Add missing protocol errors --- src/realm/error_codes.cpp | 2 ++ src/realm/error_codes.h | 7 +++++++ src/realm/sync/protocol.cpp | 15 +++++++++++++++ src/realm/sync/protocol.hpp | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/src/realm/error_codes.cpp b/src/realm/error_codes.cpp index d137afc28f4..ebed22b32b1 100644 --- a/src/realm/error_codes.cpp +++ b/src/realm/error_codes.cpp @@ -393,6 +393,8 @@ static const constexpr MapElem string_to_error_code[] = { {"SyncConnectFailed", ErrorCodes::SyncConnectFailed}, {"SyncConnectTimeout", ErrorCodes::SyncConnectTimeout}, {"SyncInvalidSchemaChange", ErrorCodes::SyncInvalidSchemaChange}, + {"SyncLocalClockBeforeEpoch", ErrorCodes::SyncLocalClockBeforeEpoch}, + {"SyncSchemaMigrationError", ErrorCodes::SyncSchemaMigrationError}, {"SyncPermissionDenied", ErrorCodes::SyncPermissionDenied}, {"SyncProtocolInvariantFailed", ErrorCodes::SyncProtocolInvariantFailed}, {"SyncProtocolNegotiationFailed", ErrorCodes::SyncProtocolNegotiationFailed}, diff --git a/src/realm/error_codes.h b/src/realm/error_codes.h index 4b0a85bcd87..bbc65e94577 100644 --- a/src/realm/error_codes.h +++ b/src/realm/error_codes.h @@ -266,9 +266,16 @@ typedef enum realm_sync_errno_session { RLM_SYNC_ERR_SESSION_REVERT_TO_PBS = 234, RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION = 235, RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED = 236, + RLM_SYNC_ERR_SESSION_FIELD_LVL_PERMS_NOT_SUPPORTED = 238, + RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_FORCE_UPGRADE = 239, // Error code 299 is reserved as an "unknown session error" in tests } realm_sync_errno_session_e; +// These errors are intended for the edge server and are an error if received by a sync client +typedef enum realm_sync_errno_edge_e { + RLM_SYNC_ERR_EDGE_REBOOT = 237, +} realm_sync_errno_edge; + typedef enum realm_web_socket_errno { RLM_ERR_WEBSOCKET_OK = 1000, RLM_ERR_WEBSOCKET_GOINGAWAY = 1001, diff --git a/src/realm/sync/protocol.cpp b/src/realm/sync/protocol.cpp index 525604f7853..d6b7765c945 100644 --- a/src/realm/sync/protocol.cpp +++ b/src/realm/sync/protocol.cpp @@ -128,6 +128,15 @@ const char* get_protocol_error_message(int error_code) noexcept case ProtocolError::schema_version_changed: return "Client opened a session with a new valid schema version - migrating client to use new schema " "version (BIND)"; + case ProtocolError::edge_reboot: + return "Error used to reboot the Edge Server. This error should only be sent to the Edge Server " + "and no other clients."; + case ProtocolError::field_perms_not_supported: + return "Client tried to make a read or write with a role that contains field-level permissions which " + "are not supported on edge wireprotocol"; + case ProtocolError::schema_version_force_upgrade: + return "Server has forcefully bumped client's schema version because it does not support schema " + "versioning"; } return nullptr; } @@ -164,6 +173,8 @@ Status protocol_error_to_status(ProtocolError error_code, std::string_view msg) [[fallthrough]]; case ProtocolError::bad_changeset_size: [[fallthrough]]; + case ProtocolError::field_perms_not_supported: + [[fallthrough]]; case ProtocolError::bad_message_order: return ErrorCodes::SyncProtocolInvariantFailed; case ProtocolError::bad_decompression: @@ -222,6 +233,8 @@ Status protocol_error_to_status(ProtocolError error_code, std::string_view msg) case ProtocolError::bad_schema_version: [[fallthrough]]; case ProtocolError::schema_version_changed: + [[fallthrough]]; + case ProtocolError::schema_version_force_upgrade: return ErrorCodes::SyncSchemaMigrationError; case ProtocolError::limits_exceeded: @@ -247,6 +260,8 @@ Status protocol_error_to_status(ProtocolError error_code, std::string_view msg) case ProtocolError::user_blacklisted: [[fallthrough]]; case ProtocolError::transact_before_upload: + [[fallthrough]]; + case ProtocolError::edge_reboot: REALM_UNREACHABLE(); } return ErrorCodes::UnknownError; diff --git a/src/realm/sync/protocol.hpp b/src/realm/sync/protocol.hpp index eab452bdf2f..07f03acb1e6 100644 --- a/src/realm/sync/protocol.hpp +++ b/src/realm/sync/protocol.hpp @@ -425,6 +425,11 @@ enum class ProtocolError { revert_to_pbs = RLM_SYNC_ERR_SESSION_REVERT_TO_PBS, // Server rolled back to PBS after FLX migration - revert FLX client migration (BIND) bad_schema_version = RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION, // Client tried to open a session with an invalid schema version (BIND) schema_version_changed = RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED, // Client opened a session with a new valid schema version - migrate client to use new schema version (BIND) + field_perms_not_supported = RLM_SYNC_ERR_SESSION_FIELD_LVL_PERMS_NOT_SUPPORTED, // Client tried to make a read or write with a role that contains field-level permissions which are not supported on edge wireprotocol. + schema_version_force_upgrade = RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_FORCE_UPGRADE, // Server has forcefully bumped client's schema version because it does not support schema versioning + + // Edge Server errors - not supported + edge_reboot = RLM_SYNC_ERR_EDGE_REBOOT, // Error used to reboot the Edge Server. This error should only be sent to the Edge Server and no other clients. // clang-format on }; From 2325c66e794b540f12633551760141b0fa7b9048 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Mon, 12 Aug 2024 16:01:51 -0400 Subject: [PATCH 2/4] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb1662db8f..185ed50ad27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### Internals * Update TestAppSession to allow scope-based usage for restarting the local app resources. ([PR #7672](https://github.com/realm/realm-core/pull/7672)) +* Added definitions for missing protocol errors reported by the server. ([PR #7982](https://github.com/realm/realm-core/pull/7982)) ---------------------------------------------- From a67f0414b439e7ff9dc7bf8aeedc250c6169cffe Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Mon, 12 Aug 2024 16:15:57 -0400 Subject: [PATCH 3/4] error_code_to_string was out of order - cut and paste error --- src/realm/error_codes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/realm/error_codes.cpp b/src/realm/error_codes.cpp index ebed22b32b1..6ba7972c118 100644 --- a/src/realm/error_codes.cpp +++ b/src/realm/error_codes.cpp @@ -394,10 +394,10 @@ static const constexpr MapElem string_to_error_code[] = { {"SyncConnectTimeout", ErrorCodes::SyncConnectTimeout}, {"SyncInvalidSchemaChange", ErrorCodes::SyncInvalidSchemaChange}, {"SyncLocalClockBeforeEpoch", ErrorCodes::SyncLocalClockBeforeEpoch}, - {"SyncSchemaMigrationError", ErrorCodes::SyncSchemaMigrationError}, {"SyncPermissionDenied", ErrorCodes::SyncPermissionDenied}, {"SyncProtocolInvariantFailed", ErrorCodes::SyncProtocolInvariantFailed}, {"SyncProtocolNegotiationFailed", ErrorCodes::SyncProtocolNegotiationFailed}, + {"SyncSchemaMigrationError", ErrorCodes::SyncSchemaMigrationError}, {"SyncServerPermissionsChanged", ErrorCodes::SyncServerPermissionsChanged}, {"SyncUserMismatch", ErrorCodes::SyncUserMismatch}, {"SyncWriteNotAllowed", ErrorCodes::SyncWriteNotAllowed}, From 9f26b149556d01718da68165a0ab0c6155f39b7b Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Mon, 12 Aug 2024 22:19:38 -0400 Subject: [PATCH 4/4] Updates from review --- src/realm/error_codes.cpp | 1 + src/realm/error_codes.h | 8 ++------ src/realm/sync/protocol.cpp | 10 ---------- src/realm/sync/protocol.hpp | 4 ---- 4 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/realm/error_codes.cpp b/src/realm/error_codes.cpp index 6ba7972c118..b3aa6b64c96 100644 --- a/src/realm/error_codes.cpp +++ b/src/realm/error_codes.cpp @@ -409,6 +409,7 @@ static const constexpr MapElem string_to_error_code[] = { {"TwilioError", ErrorCodes::TwilioError}, {"TypeMismatch", ErrorCodes::TypeMismatch}, {"UnexpectedPrimaryKey", ErrorCodes::UnexpectedPrimaryKey}, + // UnknownError intentionally left out of list {"UnsupportedFileFormatVersion", ErrorCodes::UnsupportedFileFormatVersion}, {"UserAlreadyConfirmed", ErrorCodes::UserAlreadyConfirmed}, {"UserAppDomainMismatch", ErrorCodes::UserAppDomainMismatch}, diff --git a/src/realm/error_codes.h b/src/realm/error_codes.h index bbc65e94577..e27fe366e64 100644 --- a/src/realm/error_codes.h +++ b/src/realm/error_codes.h @@ -266,16 +266,12 @@ typedef enum realm_sync_errno_session { RLM_SYNC_ERR_SESSION_REVERT_TO_PBS = 234, RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION = 235, RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED = 236, - RLM_SYNC_ERR_SESSION_FIELD_LVL_PERMS_NOT_SUPPORTED = 238, + // Error code 237 is not used by the client + // Error code 238 is not used by the sync protocol RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_FORCE_UPGRADE = 239, // Error code 299 is reserved as an "unknown session error" in tests } realm_sync_errno_session_e; -// These errors are intended for the edge server and are an error if received by a sync client -typedef enum realm_sync_errno_edge_e { - RLM_SYNC_ERR_EDGE_REBOOT = 237, -} realm_sync_errno_edge; - typedef enum realm_web_socket_errno { RLM_ERR_WEBSOCKET_OK = 1000, RLM_ERR_WEBSOCKET_GOINGAWAY = 1001, diff --git a/src/realm/sync/protocol.cpp b/src/realm/sync/protocol.cpp index d6b7765c945..7803403e86d 100644 --- a/src/realm/sync/protocol.cpp +++ b/src/realm/sync/protocol.cpp @@ -128,12 +128,6 @@ const char* get_protocol_error_message(int error_code) noexcept case ProtocolError::schema_version_changed: return "Client opened a session with a new valid schema version - migrating client to use new schema " "version (BIND)"; - case ProtocolError::edge_reboot: - return "Error used to reboot the Edge Server. This error should only be sent to the Edge Server " - "and no other clients."; - case ProtocolError::field_perms_not_supported: - return "Client tried to make a read or write with a role that contains field-level permissions which " - "are not supported on edge wireprotocol"; case ProtocolError::schema_version_force_upgrade: return "Server has forcefully bumped client's schema version because it does not support schema " "versioning"; @@ -173,8 +167,6 @@ Status protocol_error_to_status(ProtocolError error_code, std::string_view msg) [[fallthrough]]; case ProtocolError::bad_changeset_size: [[fallthrough]]; - case ProtocolError::field_perms_not_supported: - [[fallthrough]]; case ProtocolError::bad_message_order: return ErrorCodes::SyncProtocolInvariantFailed; case ProtocolError::bad_decompression: @@ -260,8 +252,6 @@ Status protocol_error_to_status(ProtocolError error_code, std::string_view msg) case ProtocolError::user_blacklisted: [[fallthrough]]; case ProtocolError::transact_before_upload: - [[fallthrough]]; - case ProtocolError::edge_reboot: REALM_UNREACHABLE(); } return ErrorCodes::UnknownError; diff --git a/src/realm/sync/protocol.hpp b/src/realm/sync/protocol.hpp index 07f03acb1e6..005a672f6eb 100644 --- a/src/realm/sync/protocol.hpp +++ b/src/realm/sync/protocol.hpp @@ -425,12 +425,8 @@ enum class ProtocolError { revert_to_pbs = RLM_SYNC_ERR_SESSION_REVERT_TO_PBS, // Server rolled back to PBS after FLX migration - revert FLX client migration (BIND) bad_schema_version = RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION, // Client tried to open a session with an invalid schema version (BIND) schema_version_changed = RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED, // Client opened a session with a new valid schema version - migrate client to use new schema version (BIND) - field_perms_not_supported = RLM_SYNC_ERR_SESSION_FIELD_LVL_PERMS_NOT_SUPPORTED, // Client tried to make a read or write with a role that contains field-level permissions which are not supported on edge wireprotocol. schema_version_force_upgrade = RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_FORCE_UPGRADE, // Server has forcefully bumped client's schema version because it does not support schema versioning - // Edge Server errors - not supported - edge_reboot = RLM_SYNC_ERR_EDGE_REBOOT, // Error used to reboot the Edge Server. This error should only be sent to the Edge Server and no other clients. - // clang-format on };