From c50bd99d7f5554639b6a3a5563bba32ce2c87ffb Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 15 Jul 2024 12:50:31 +0200 Subject: Ensure config builders always have a valid state ...by making the respective Build methods const. It should be perfectly valid for multiple Build calls to happen for the same builder instance, so its internal state should never be invalidated by, e.g., moving from internal fields. --- src/buildtool/serve_api/remote/config.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/buildtool/serve_api/remote/config.hpp') diff --git a/src/buildtool/serve_api/remote/config.hpp b/src/buildtool/serve_api/remote/config.hpp index d19e7699..005d56af 100644 --- a/src/buildtool/serve_api/remote/config.hpp +++ b/src/buildtool/serve_api/remote/config.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -93,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 + [[nodiscard]] auto Build() const noexcept -> expected { // To not duplicate default arguments of RemoteServeConfig in builder, // create a default config and copy default arguments from there. @@ -111,7 +112,12 @@ class RemoteServeConfig::Builder final { auto known_repositories = default_config.known_repositories; if (known_repositories_.has_value()) { - known_repositories = std::move(*known_repositories_); + try { + known_repositories = *known_repositories_; + } catch (std::exception const& ex) { + return unexpected{ + std::string("Setting known repositories failed.")}; + } } auto jobs = default_config.jobs; -- cgit v1.2.3