From 90aa957ca9b7c217af7569009d1675e0f3ff8e9b Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Thu, 26 Jun 2025 20:47:45 +0100 Subject: ucl, config: use monadic error handling more --- nihil.config/write.cc | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'nihil.config/write.cc') diff --git a/nihil.config/write.cc b/nihil.config/write.cc index 2b451bd..8c02c43 100644 --- a/nihil.config/write.cc +++ b/nihil.config/write.cc @@ -4,43 +4,36 @@ module; +#include #include #include #include #include +module nihil.config; + import nihil; import nihil.ucl; -module nihil.config; - namespace nihil::config { auto write_to(std::filesystem::path const &filename) - -> std::expected -try { + -> std::expected +{ auto uclconfig = ucl::map(); // Add all the options to the UCL object. for (auto const &option : store::get().all()) { - if (option.is_default()) + if (option->is_default()) continue; - uclconfig.insert({option.name(), option.to_ucl()}); + auto uobj = co_await option->ucl(); + uclconfig.insert({option->name(), uobj}); } auto ucl_text = std::format("{:c}", uclconfig); - auto ret = safe_write_file(filename, ucl_text); - if (!ret) - return std::unexpected(nihil::error( - std::format("cannot write {}", filename.string()), - ret.error())); - - return {}; -} catch (ucl::error const &exc) { - return std::unexpected(nihil::error( - "failed to serialize configuration", - nihil::error(exc.what()))); + co_await safe_write_file(filename, ucl_text); + co_return {}; } }; -- cgit v1.2.3