From 8c9cae72e3d16a073c229f3a29914f77bae5dbb6 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Date: Wed, 17 May 2023 10:22:57 +0200 Subject: [PATCH] rgw/sfs: Throw std::system_error in type bindings This is so we throw the same kind of exception that all the sqliteorm code and it's easier to catch them. Signed-off-by: Xavi Garcia --- src/rgw/driver/sfs/sqlite/bindings/enum.h | 6 ++++-- src/rgw/driver/sfs/sqlite/bindings/real_time.h | 4 ++-- src/rgw/driver/sfs/sqlite/bindings/uuid_d.h | 7 +++++-- src/test/rgw/sfs/test_rgw_sfs_sqlite_versioned_objects.cc | 7 ++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/rgw/driver/sfs/sqlite/bindings/enum.h b/src/rgw/driver/sfs/sqlite/bindings/enum.h index 76ca9c78e1dc3..a2ff42be0e9c1 100644 --- a/src/rgw/driver/sfs/sqlite/bindings/enum.h +++ b/src/rgw/driver/sfs/sqlite/bindings/enum.h @@ -45,7 +45,8 @@ template struct row_extractor>::type> { T extract(uint row_value) const { if (row_value > static_cast(T::LAST_VALUE)) { - throw(std::runtime_error( + throw(std::system_error( + ERANGE, std::system_category(), "Invalid enum value found: (" + std::to_string(row_value) + ")" )); } @@ -55,7 +56,8 @@ struct row_extractor>::type> { T extract(sqlite3_stmt* stmt, int columnIndex) const { auto int_value = sqlite3_column_int(stmt, columnIndex); if (int_value < 0) { - throw(std::runtime_error( + throw(std::system_error( + ERANGE, std::system_category(), "Invalid enum value found: (" + std::to_string(int_value) + ")" )); } diff --git a/src/rgw/driver/sfs/sqlite/bindings/real_time.h b/src/rgw/driver/sfs/sqlite/bindings/real_time.h index 4bfc4281387b1..470d51f1d8e22 100644 --- a/src/rgw/driver/sfs/sqlite/bindings/real_time.h +++ b/src/rgw/driver/sfs/sqlite/bindings/real_time.h @@ -34,7 +34,7 @@ static int64_t time_point_to_int64(const ceph::real_time& t) { oss << "Error converting ceph::real_time to int64. " "Nanoseconds value: " << nanos << " is out of range"; - throw std::runtime_error(oss.str()); + throw std::system_error(ERANGE, std::system_category(), oss.str()); } // we can safely static_cast to int64_t now return static_cast(nanos); @@ -48,7 +48,7 @@ static ceph::real_time time_point_from_int64(int64_t value) { oss << "Error converting int64 nanoseconds value to " "ceph::real_cock::time_point. Value: " << value << " is out of range"; - throw std::runtime_error(oss.str()); + throw std::system_error(ERANGE, std::system_category(), oss.str()); } uint64_t uint64_nanos = static_cast(value); return ceph::real_time(std::chrono::nanoseconds(uint64_nanos)); diff --git a/src/rgw/driver/sfs/sqlite/bindings/uuid_d.h b/src/rgw/driver/sfs/sqlite/bindings/uuid_d.h index e76d2c63d439f..70a295a76b229 100644 --- a/src/rgw/driver/sfs/sqlite/bindings/uuid_d.h +++ b/src/rgw/driver/sfs/sqlite/bindings/uuid_d.h @@ -42,14 +42,17 @@ struct row_extractor { if (row_value) { uuid_d ret_value; if (!ret_value.parse(row_value)) { - throw std::runtime_error( + throw std::system_error( + ERANGE, std::system_category(), "incorrect uuid string (" + std::string(row_value) + ")" ); } return ret_value; } else { // ! row_value - throw std::runtime_error("incorrect uuid string (nullptr)"); + throw std::system_error( + ERANGE, std::system_category(), "incorrect uuid string (nullptr)" + ); } } diff --git a/src/test/rgw/sfs/test_rgw_sfs_sqlite_versioned_objects.cc b/src/test/rgw/sfs/test_rgw_sfs_sqlite_versioned_objects.cc index ce52d18710bd4..b376d4fa78ab3 100644 --- a/src/test/rgw/sfs/test_rgw_sfs_sqlite_versioned_objects.cc +++ b/src/test/rgw/sfs/test_rgw_sfs_sqlite_versioned_objects.cc @@ -726,15 +726,16 @@ TEST_F(TestSFSSQLiteVersionedObjects, StoreUnsupportedTimestamp) { try { storage.replace(db_version); ; - } catch (const std::runtime_error& e) { + } catch (const std::system_error& e) { EXPECT_STREQ( "Error converting ceph::real_time to int64. Nanoseconds value: " - "9223372036854775808 is out of range", + "9223372036854775808 is out of range: Numerical result out of " + "range", e.what() ); throw; } }, - std::runtime_error + std::system_error ); }