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

More detailed error message for SystemError exceptions #6756

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
* Prebuilt binaries for non-Apple platforms are no longer published as nothing was using them ([PR #6746](https://github.com/realm/realm-core/pull/6746)).
* SystemError exceptions now have a more detailed error message. ([#6739](https://github.com/realm/realm-core/issues/6739))

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

Expand Down
3 changes: 2 additions & 1 deletion src/realm/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ class FileAccessError : public RuntimeError {

struct SystemError : RuntimeError {
SystemError(std::error_code err, std::string_view msg)
: RuntimeError(ErrorCodes::SystemError, msg)
: RuntimeError(ErrorCodes::SystemError,
util::format("%1 (SystemError %2: %3)", msg, err.value(), err.message()))
{
const_cast<Status&>(to_status()).set_std_error_code(err);
}
Expand Down
11 changes: 7 additions & 4 deletions test/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,8 @@ TEST_CASE("app: sync integration", "[sync][app][baas]") {
sync_error_handler_called.store(true);
REQUIRE(error.get_system_error() ==
sync::make_error_code(realm::sync::ProtocolError::bad_authentication));
REQUIRE(error.reason() == "Unable to refresh the user access token.");
REQUIRE_THAT(std::string(error.reason()),
Catch::Matchers::ContainsSubstring("Unable to refresh the user access token."));
};
auto r = Realm::get_shared_realm(config);
timed_wait_for([&] {
Expand Down Expand Up @@ -2871,7 +2872,8 @@ TEST_CASE("app: sync integration", "[sync][app][baas]") {
sync_error_handler_called.store(true);
REQUIRE(error.get_system_error() ==
sync::make_error_code(realm::sync::ProtocolError::bad_authentication));
REQUIRE(error.reason() == "Unable to refresh the user access token.");
REQUIRE_THAT(std::string(error.reason()),
Catch::Matchers::ContainsSubstring("Unable to refresh the user access token."));
};

auto transport = static_cast<SynchronousTestTransport*>(session.transport());
Expand Down Expand Up @@ -3101,8 +3103,9 @@ TEST_CASE("app: sync integration", "[sync][app][baas]") {

auto error = wait_for_future(std::move(pf.future), std::chrono::minutes(5)).get();
REQUIRE(error.get_system_error() == make_error_code(sync::ProtocolError::limits_exceeded));
REQUIRE(error.reason() == "Sync websocket closed because the server received a message that was too large: "
"read limited at 16777217 bytes");
REQUIRE_THAT(std::string(error.reason()),
Catch::Matchers::ContainsSubstring("Sync websocket closed because the server received a message "
"that was too large: read limited at 16777217 bytes"));
REQUIRE(error.is_client_reset_requested());
REQUIRE(error.server_requests_action == sync::ProtocolErrorInfo::Action::ClientReset);
}
Expand Down
9 changes: 9 additions & 0 deletions test/test_util_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,13 @@ TEST(Utils_File_Lock)
CHECK_NOT(f2.try_rw_lock_exclusive());
}

TEST(Utils_File_SystemErrorMessage)
{
std::error_code err = std::make_error_code(std::errc::too_many_files_open);
std::string_view message = "my message";
std::string expected = util::format("%1 (SystemError %2: %3)", message, err.value(), "Too many open files");
Copy link
Member

Choose a reason for hiding this comment

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

CHECK_STRING_CONTAINS(e.what(), expected) failed with (my message (SystemError 24: too many files open), my message (SystemError 24: Too many open files)) ... Only on Windows though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Windows seems to provide a slightly different error message, so I've adjusted the tests accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course Windows just has to be different

CHECK_THROW_CONTAINING_MESSAGE(throw SystemError(err, message), expected);
CHECK_THROW_CONTAINING_MESSAGE(throw SystemError(err.value(), message), expected);
}

#endif