diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-25 21:15:34 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-25 21:15:34 +0100 |
| commit | 257b6719ed89104018f6a521f6141ecd3eec3fd9 (patch) | |
| tree | 590217da5f5131494ee3f002b44da25fa600a96d /nihil.config/write.cc | |
| parent | 0fc4b95e63370b9131c4e76f5f7137a4764dc341 (diff) | |
| download | nihil-257b6719ed89104018f6a521f6141ecd3eec3fd9.tar.gz nihil-257b6719ed89104018f6a521f6141ecd3eec3fd9.tar.bz2 | |
nihil: add an error type
Diffstat (limited to 'nihil.config/write.cc')
| -rw-r--r-- | nihil.config/write.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/nihil.config/write.cc b/nihil.config/write.cc index 4b2a232..2b451bd 100644 --- a/nihil.config/write.cc +++ b/nihil.config/write.cc @@ -4,6 +4,7 @@ module; +#include <expected> #include <filesystem> #include <format> #include <utility> @@ -15,7 +16,8 @@ module nihil.config; namespace nihil::config { -auto write_to(std::filesystem::path const &filename) -> void +auto write_to(std::filesystem::path const &filename) + -> std::expected<void, nihil::error> try { auto uclconfig = ucl::map<ucl::object>(); @@ -30,10 +32,15 @@ try { auto ucl_text = std::format("{:c}", uclconfig); auto ret = safe_write_file(filename, ucl_text); if (!ret) - throw error(std::format("{}: {}", filename.string(), - ret.error().message())); + return std::unexpected(nihil::error( + std::format("cannot write {}", filename.string()), + ret.error())); + + return {}; } catch (ucl::error const &exc) { - throw error(std::format("{}: {}", filename.string(), exc.what())); + return std::unexpected(nihil::error( + "failed to serialize configuration", + nihil::error(exc.what()))); } }; |
