Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing protocol errors #7982

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

----------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions src/realm/error_codes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ static const constexpr MapElem string_to_error_code[] = {
{"SyncConnectFailed", ErrorCodes::SyncConnectFailed},
{"SyncConnectTimeout", ErrorCodes::SyncConnectTimeout},
{"SyncInvalidSchemaChange", ErrorCodes::SyncInvalidSchemaChange},
{"SyncLocalClockBeforeEpoch", ErrorCodes::SyncLocalClockBeforeEpoch},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never added to the string_to_error_code array.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the new errors be added to this map? and also assign error categories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reusing existing ErrorCode values and the two added to this list were already assigned error categories (they were just left off this list - I just verified the list and the only other one missing is UnknownError this seems to be intentional).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this error even mean?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an error I added. We use 2015-01-01 as epoch and count the milliseconds since then for the changesets' timestamp. This error is thrown when the local clock is set before that date.

{"SyncPermissionDenied", ErrorCodes::SyncPermissionDenied},
{"SyncProtocolInvariantFailed", ErrorCodes::SyncProtocolInvariantFailed},
{"SyncProtocolNegotiationFailed", ErrorCodes::SyncProtocolNegotiationFailed},
{"SyncSchemaMigrationError", ErrorCodes::SyncSchemaMigrationError},
{"SyncServerPermissionsChanged", ErrorCodes::SyncServerPermissionsChanged},
{"SyncUserMismatch", ErrorCodes::SyncUserMismatch},
{"SyncWriteNotAllowed", ErrorCodes::SyncWriteNotAllowed},
Expand All @@ -407,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},
Expand Down
3 changes: 3 additions & 0 deletions src/realm/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ 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,
// 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;

Expand Down
5 changes: 5 additions & 0 deletions src/realm/sync/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ 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::schema_version_force_upgrade:
return "Server has forcefully bumped client's schema version because it does not support schema "
"versioning";
}
return nullptr;
}
Expand Down Expand Up @@ -222,6 +225,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:
Expand Down
1 change: 1 addition & 0 deletions src/realm/sync/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ 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)
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

// clang-format on
};
Expand Down
Loading