From 257b6719ed89104018f6a521f6141ecd3eec3fd9 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Wed, 25 Jun 2025 21:15:34 +0100 Subject: nihil: add an error type --- nihil.config/write.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'nihil.config/write.cc') 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 #include #include #include @@ -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 try { auto uclconfig = ucl::map(); @@ -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()))); } }; -- cgit v1.2.3