refactor: Use std::expected instead of std::variant for errors (#2160)

This commit is contained in:
Ayaz Salikhov
2025-06-03 13:34:25 +01:00
committed by GitHub
parent 19257f8aa9
commit 550f0fae85
40 changed files with 295 additions and 310 deletions

View File

@@ -258,13 +258,11 @@ TEST_P(RPCEngineFlowParameterTest, Test)
);
auto const res = engine->buildResponse(ctx);
auto const status = std::get_if<rpc::Status>(&res.response);
auto const response = std::get_if<boost::json::object>(&res.response);
ASSERT_EQ(status == nullptr, testBundle.response.has_value());
ASSERT_EQ(res.response.has_value(), testBundle.response.has_value());
if (testBundle.response.has_value()) {
EXPECT_EQ(*response, testBundle.response.value());
EXPECT_EQ(res.response.value(), testBundle.response.value());
} else {
EXPECT_EQ(*status, testBundle.status.value());
EXPECT_EQ(res.response.error(), testBundle.status.value());
}
});
}
@@ -295,9 +293,8 @@ TEST_F(RPCEngineTest, ThrowDatabaseError)
);
auto const res = engine->buildResponse(ctx);
auto const status = std::get_if<rpc::Status>(&res.response);
ASSERT_TRUE(status != nullptr);
EXPECT_EQ(*status, Status{RippledError::rpcTOO_BUSY});
ASSERT_FALSE(res.response.has_value());
EXPECT_EQ(res.response.error(), Status{RippledError::rpcTOO_BUSY});
});
}
@@ -327,9 +324,8 @@ TEST_F(RPCEngineTest, ThrowException)
);
auto const res = engine->buildResponse(ctx);
auto const status = std::get_if<rpc::Status>(&res.response);
ASSERT_TRUE(status != nullptr);
EXPECT_EQ(*status, Status{RippledError::rpcINTERNAL});
ASSERT_FALSE(res.response.has_value());
EXPECT_EQ(res.response.error(), Status{RippledError::rpcINTERNAL});
});
}
@@ -454,8 +450,8 @@ TEST_P(RPCEngineCacheParameterTest, Test)
);
auto const res = engine->buildResponse(ctx);
auto const response = std::get_if<boost::json::object>(&res.response);
EXPECT_EQ(*response, boost::json::parse(R"JSON({ "computed": "world_50"})JSON").as_object());
ASSERT_TRUE(res.response.has_value());
EXPECT_EQ(res.response.value(), boost::json::parse(R"JSON({ "computed": "world_50"})JSON").as_object());
});
}
}
@@ -499,9 +495,8 @@ TEST_F(RPCEngineTest, NotCacheIfErrorHappen)
);
auto const res = engine->buildResponse(ctx);
auto const error = std::get_if<rpc::Status>(&res.response);
ASSERT_NE(error, nullptr);
EXPECT_EQ(*error, rpc::Status{"Very custom error"});
ASSERT_FALSE(res.response.has_value());
EXPECT_EQ(res.response.error(), rpc::Status{"Very custom error"});
});
}
}