summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-15 12:50:31 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-16 17:51:12 +0200
commitc50bd99d7f5554639b6a3a5563bba32ce2c87ffb (patch)
treed9ad9d6f43be43cda306a275cfe6cc0b66633207 /src
parent5af6aa0659c833081eb16fe5c743f3080fe54be9 (diff)
downloadjustbuild-c50bd99d7f5554639b6a3a5563bba32ce2c87ffb.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/auth/authentication.hpp2
-rw-r--r--src/buildtool/serve_api/remote/config.hpp10
2 files changed, 9 insertions, 3 deletions
diff --git a/src/buildtool/auth/authentication.hpp b/src/buildtool/auth/authentication.hpp
index cd4ff86d..f06e6a1c 100644
--- a/src/buildtool/auth/authentication.hpp
+++ b/src/buildtool/auth/authentication.hpp
@@ -84,7 +84,7 @@ class Auth::TLS::Builder final {
/// tls_client_key are set, or none of the two.
/// \return Auth on success, error string on failure, nullopt if no TLS
/// configuration fields were set.
- [[nodiscard]] auto Build() noexcept
+ [[nodiscard]] auto Build() const noexcept
-> std::optional<expected<Auth, std::string>> {
// To not duplicate default arguments of Auth::TLS in builder,
// create a default config and copy default arguments from there.
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 <chrono>
#include <cstddef>
+#include <exception>
#include <filesystem>
#include <iterator>
#include <optional>
@@ -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<RemoteServeConfig, std::string> {
// 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;