diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-26 20:47:45 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-26 20:47:45 +0100 |
| commit | 90aa957ca9b7c217af7569009d1675e0f3ff8e9b (patch) | |
| tree | e6a61ca2b6928e6414372b9b1484ce80fa2fb0b3 /nihil.config/write.cc | |
| parent | 1db86c401df11423c945634d8b2a483e97afa878 (diff) | |
| download | nihil-90aa957ca9b7c217af7569009d1675e0f3ff8e9b.tar.gz nihil-90aa957ca9b7c217af7569009d1675e0f3ff8e9b.tar.bz2 | |
ucl, config: use monadic error handling more
Diffstat (limited to 'nihil.config/write.cc')
| -rw-r--r-- | nihil.config/write.cc | 27 |
1 files changed, 10 insertions, 17 deletions
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 <coroutine> #include <expected> #include <filesystem> #include <format> #include <utility> +module nihil.config; + import nihil; import nihil.ucl; -module nihil.config; - namespace nihil::config { auto write_to(std::filesystem::path const &filename) - -> std::expected<void, nihil::error> -try { + -> std::expected<void, error> +{ auto uclconfig = ucl::map<ucl::object>(); // 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 {}; } }; |
