Skip to content

Commit

Permalink
Update websocket error messages to be more descriptive (#6298)
Browse files Browse the repository at this point in the history
* Pass the reason as the SyncError message

* Updated changelog and read/write error messages

* Updated changelog message

* read_or_write_error message no longer optional

* Updated changelog after release
  • Loading branch information
Michael Wilkerson-Barker authored Feb 15, 2023
1 parent e2dba2a commit f447145
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* `File::get_unique_id` now works on Windows
* Replaced manual path string conversion with `std::filesystem::path`
* Update yarn download path in install_baas.sh ([PR #6309](https://github.com/realm/realm-core/pull/6309))
* Include the websocket close status reason when reporting errors to the sync client ([PR #6298](https://github.com/realm/realm-core/pull/6298))

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

Expand Down
20 changes: 10 additions & 10 deletions src/realm/sync/noinst/client_impl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ bool Connection::websocket_binary_message_received(util::Span<const char> data)
std::error_code ec;
using sf = SimulatedFailure;
if (sf::trigger(sf::sync_client__read_head, ec)) {
read_or_write_error(ec);
read_or_write_error(ec, "simulated read error");
return bool(m_websocket);
}

Expand Down Expand Up @@ -472,7 +472,7 @@ bool Connection::websocket_closed_handler(bool was_clean, Status status)
involuntary_disconnect(SessionErrorInfo{error_code, try_again}); // Throws
}
else if (status_code == ErrorCodes::ReadError || status_code == ErrorCodes::WriteError) {
read_or_write_error(error_code);
read_or_write_error(error_code, status.reason());
}
else if (status_code == ErrorCodes::WebSocket_GoingAway || status_code == ErrorCodes::WebSocket_ProtocolError ||
status_code == ErrorCodes::WebSocket_UnsupportedData || status_code == ErrorCodes::WebSocket_Reserved ||
Expand All @@ -498,30 +498,30 @@ bool Connection::websocket_closed_handler(bool was_clean, Status status)
error_code = ClientError::ssl_server_cert_rejected;
constexpr bool is_fatal = true;
m_reconnect_info.m_reason = ConnectionTerminationReason::ssl_certificate_rejected;
close_due_to_client_side_error(error_code, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(error_code, status.reason(), is_fatal); // Throws
}
else if (status_code == ErrorCodes::WebSocket_Client_Too_Old) {
error_code = ClientError::client_too_old_for_server;
constexpr bool is_fatal = true;
m_reconnect_info.m_reason = ConnectionTerminationReason::http_response_says_fatal_error;
close_due_to_client_side_error(error_code, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(error_code, status.reason(), is_fatal); // Throws
}
else if (status_code == ErrorCodes::WebSocket_Client_Too_New) {
error_code = ClientError::client_too_new_for_server;
constexpr bool is_fatal = true;
m_reconnect_info.m_reason = ConnectionTerminationReason::http_response_says_fatal_error;
close_due_to_client_side_error(error_code, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(error_code, status.reason(), is_fatal); // Throws
}
else if (status_code == ErrorCodes::WebSocket_Protocol_Mismatch) {
error_code = ClientError::protocol_mismatch;
constexpr bool is_fatal = true;
m_reconnect_info.m_reason = ConnectionTerminationReason::http_response_says_fatal_error;
close_due_to_client_side_error(error_code, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(error_code, status.reason(), is_fatal); // Throws
}
else if (status_code == ErrorCodes::WebSocket_Fatal_Error || status_code == ErrorCodes::WebSocket_Forbidden) {
constexpr bool is_fatal = true;
m_reconnect_info.m_reason = ConnectionTerminationReason::http_response_says_fatal_error;
close_due_to_client_side_error(error_code, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(error_code, status.reason(), is_fatal); // Throws
}
else if (status_code == ErrorCodes::WebSocket_Unauthorized ||
status_code == ErrorCodes::WebSocket_MovedPermanently ||
Expand All @@ -530,7 +530,7 @@ bool Connection::websocket_closed_handler(bool was_clean, Status status)
status_code == ErrorCodes::WebSocket_Retry_Error) {
constexpr bool is_fatal = false;
m_reconnect_info.m_reason = ConnectionTerminationReason::http_response_says_nonfatal_error;
close_due_to_client_side_error(error_code, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(error_code, status.reason(), is_fatal); // Throws
}

return bool(m_websocket);
Expand Down Expand Up @@ -1153,11 +1153,11 @@ void Connection::handle_disconnect_wait(Status status)
}


void Connection::read_or_write_error(std::error_code ec)
void Connection::read_or_write_error(std::error_code ec, std::string_view msg)
{
m_reconnect_info.m_reason = ConnectionTerminationReason::read_or_write_error;
bool is_fatal = false;
close_due_to_client_side_error(ec, std::nullopt, is_fatal); // Throws
close_due_to_client_side_error(ec, msg, is_fatal); // Throws
}


Expand Down
2 changes: 1 addition & 1 deletion src/realm/sync/noinst/client_impl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class ClientImpl::Connection {
void handle_message_received(util::Span<const char> data);
void initiate_disconnect_wait();
void handle_disconnect_wait(Status status);
void read_or_write_error(std::error_code);
void read_or_write_error(std::error_code ec, std::string_view msg);
void close_due_to_protocol_error(std::error_code, std::optional<std::string_view> msg = std::nullopt);
void close_due_to_client_side_error(std::error_code, std::optional<std::string_view> msg, bool is_fatal);
void close_due_to_server_side_error(ProtocolError, const ProtocolErrorInfo& info);
Expand Down

0 comments on commit f447145

Please sign in to comment.