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/read.cc | |
| parent | 0fc4b95e63370b9131c4e76f5f7137a4764dc341 (diff) | |
| download | nihil-257b6719ed89104018f6a521f6141ecd3eec3fd9.tar.gz nihil-257b6719ed89104018f6a521f6141ecd3eec3fd9.tar.bz2 | |
nihil: add an error type
Diffstat (limited to 'nihil.config/read.cc')
| -rw-r--r-- | nihil.config/read.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/nihil.config/read.cc b/nihil.config/read.cc index d55703d..3c20566 100644 --- a/nihil.config/read.cc +++ b/nihil.config/read.cc @@ -4,6 +4,7 @@ module; +#include <expected> #include <filesystem> #include <format> #include <iterator> @@ -16,7 +17,8 @@ module nihil.config; namespace nihil::config { -auto read_from(std::filesystem::path const &filename) -> void +auto read_from(std::filesystem::path const &filename) + -> std::expected<void, nihil::error> { // TODO: nihil.ucl should have a way to load UCL from a filename. @@ -26,10 +28,9 @@ auto read_from(std::filesystem::path const &filename) -> void // Ignore ENOENT, it simply means we haven't created the // config file yet, so default values will be used. if (err.error() == std::errc::no_such_file_or_directory) - return; - throw error(std::format("{}: {}", - filename.string(), - err.error().message())); + return {}; + auto errstr = std::format("cannot read {}", filename.string()); + return std::unexpected(nihil::error(errstr, err.error())); } // Parse the UCL. @@ -52,6 +53,8 @@ auto read_from(std::filesystem::path const &filename) -> void throw error(std::format("{}: {}", filename.string(), err.what())); } + + return {}; } } // namespace nihil::config |
