diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2024-06-27 17:44:34 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2024-06-28 11:34:53 +0200 |
commit | 01d9abcfc85d974763c3a7f8fed998342d92a681 (patch) | |
tree | 105a887360a49dfa8bf942f48c5560d29b0dcd6e /src/buildtool/serve_api/remote/config.hpp | |
parent | f82ee35bff7363e6381d659b26773f260109e2ea (diff) | |
download | justbuild-01d9abcfc85d974763c3a7f8fed998342d92a681.tar.gz |
Use (un)expected for serve API
Diffstat (limited to 'src/buildtool/serve_api/remote/config.hpp')
-rw-r--r-- | src/buildtool/serve_api/remote/config.hpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/buildtool/serve_api/remote/config.hpp b/src/buildtool/serve_api/remote/config.hpp index 8c46a853..d19e7699 100644 --- a/src/buildtool/serve_api/remote/config.hpp +++ b/src/buildtool/serve_api/remote/config.hpp @@ -22,12 +22,12 @@ #include <optional> #include <string> #include <utility> -#include <variant> #include <vector> #include "fmt/core.h" #include "src/buildtool/common/remote/remote_common.hpp" #include "src/buildtool/main/build_utils.hpp" +#include "src/utils/cpp/expected.hpp" struct RemoteServeConfig final { class Builder; @@ -94,7 +94,7 @@ class RemoteServeConfig::Builder final { /// \brief Finalize building and create RemoteServeConfig. /// \return RemoteServeConfig on success or an error on failure. [[nodiscard]] auto Build() noexcept - -> std::variant<RemoteServeConfig, std::string> { + -> expected<RemoteServeConfig, std::string> { // To not duplicate default arguments of RemoteServeConfig in builder, // create a default config and copy default arguments from there. RemoteServeConfig const default_config; @@ -103,8 +103,9 @@ class RemoteServeConfig::Builder final { if (remote_address_.has_value()) { remote_address = ParseAddress(*remote_address_); if (not remote_address) { - return fmt::format("Setting serve service address '{}' failed.", - *remote_address_); + return unexpected{ + fmt::format("Setting serve service address '{}' failed.", + *remote_address_)}; } } @@ -117,7 +118,7 @@ class RemoteServeConfig::Builder final { if (jobs_.has_value()) { jobs = *jobs_; if (jobs == 0) { - return "Setting jobs failed."; + return unexpected{std::string{"Setting jobs failed."}}; } } @@ -125,7 +126,7 @@ class RemoteServeConfig::Builder final { if (build_jobs_.has_value()) { build_jobs = *build_jobs_; if (build_jobs == 0) { - return "Setting build jobs failed."; + return unexpected{std::string{"Setting build jobs failed."}}; } } @@ -134,7 +135,8 @@ class RemoteServeConfig::Builder final { action_timeout = *action_timeout_; if (bool const valid = action_timeout > std::chrono::seconds{0}; not valid) { - return "Setting action timeout failed."; + return unexpected{ + std::string{"Setting action timeout failed."}}; } } |