Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
rgw/sfs: Throw std::system_error in type bindings
Browse files Browse the repository at this point in the history
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 <xavi.garcia@suse.com>
  • Loading branch information
0xavi0 committed May 17, 2023
1 parent e805143 commit 8c9cae7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/rgw/driver/sfs/sqlite/bindings/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ template <class T>
struct row_extractor<T, typename std::enable_if<std::is_enum_v<T>>::type> {
T extract(uint row_value) const {
if (row_value > static_cast<uint>(T::LAST_VALUE)) {
throw(std::runtime_error(
throw(std::system_error(
ERANGE, std::system_category(),
"Invalid enum value found: (" + std::to_string(row_value) + ")"
));
}
Expand All @@ -55,7 +56,8 @@ struct row_extractor<T, typename std::enable_if<std::is_enum_v<T>>::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) + ")"
));
}
Expand Down
4 changes: 2 additions & 2 deletions src/rgw/driver/sfs/sqlite/bindings/real_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(nanos);
Expand All @@ -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<uint64_t>(value);
return ceph::real_time(std::chrono::nanoseconds(uint64_nanos));
Expand Down
7 changes: 5 additions & 2 deletions src/rgw/driver/sfs/sqlite/bindings/uuid_d.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ struct row_extractor<uuid_d> {
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)"
);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/test/rgw/sfs/test_rgw_sfs_sqlite_versioned_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

0 comments on commit 8c9cae7

Please sign in to comment.