diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-27 12:08:58 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-27 12:08:58 +0100 |
| commit | 001c9917ace09f7b1c80d96eb067e1d37e86c546 (patch) | |
| tree | 89e360961b9659a8c6b897c5412b7d6834b8eed9 /nihil.ucl/errc.cc | |
| parent | 90aa957ca9b7c217af7569009d1675e0f3ff8e9b (diff) | |
| download | nihil-001c9917ace09f7b1c80d96eb067e1d37e86c546.tar.gz nihil-001c9917ace09f7b1c80d96eb067e1d37e86c546.tar.bz2 | |
improve error handling
Diffstat (limited to 'nihil.ucl/errc.cc')
| -rw-r--r-- | nihil.ucl/errc.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nihil.ucl/errc.cc b/nihil.ucl/errc.cc new file mode 100644 index 0000000..fc1d9f8 --- /dev/null +++ b/nihil.ucl/errc.cc @@ -0,0 +1,51 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <string> +#include <system_error> + +module nihil.ucl; + +import nihil; + +namespace nihil::ucl { + +struct ucl_error_category final : std::error_category { + auto name() const noexcept -> char const * override; + auto message(int err) const -> std::string override; +}; + +auto ucl_category() noexcept -> std::error_category & +{ + static auto category = ucl_error_category(); + return category; +} + +auto make_error_condition(errc ec) -> std::error_condition +{ + return {static_cast<int>(ec), ucl_category()}; +} + +auto ucl_error_category::name() const noexcept -> char const * +{ + return "nihil.ucl"; +} + +auto ucl_error_category::message(int err) const -> std::string +{ + switch (static_cast<errc>(err)) { + case errc::no_error: + return "No error"; + case errc::failed_to_create_object: + return "Failed to create UCL object"; + case errc::type_mismatch: + return "UCL type does not match expected type"; + default: + return "Undefined error"; + } +} + +} // namespace nihil::ucl |
