diff options
-rw-r--r-- | src/core/error.cpp | 19 | ||||
-rw-r--r-- | src/core/error.h | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/core/error.cpp b/src/core/error.cpp index e777c84..52af76f 100644 --- a/src/core/error.cpp +++ b/src/core/error.cpp @@ -15,6 +15,17 @@ error::error(error &&error) , is_critical_{std::move(error.is_critical_)} , error_message_{std::move(error.error_message_)}{} +const std::string_view error::get_category() const { + auto& reg = impl::get_error_registry(); + + auto eov = reg.search_error_category(error_code_); + SAW_ASSERT(eov.is_value()){ + return "Error category not found. Report this error to the forstio maintainer"; + } + + return eov.get_value(); +} + const std::string_view error::get_message() const { return std::visit( [this](auto &&arg) -> const std::string_view { @@ -93,6 +104,14 @@ error_registry::error_registry(): } {} +error_or<const std::string_view> error_registry::search_category(const error::code& id) const { + if(infos_.size() >= id){ + return make_error<err::not_found>(); + } + + return infos_.at(id).description; +} + error_or<error::code> error_registry::search_id(const std::string_view& desc)const{ /** * Search the index in the vector diff --git a/src/core/error.h b/src/core/error.h index d057877..e816734 100644 --- a/src/core/error.h +++ b/src/core/error.h @@ -35,6 +35,9 @@ public: error &operator=(error &&) = default; const std::string_view get_message() const; + + const std::string_view get_category() const; + bool failed() const; bool is_critical() const; @@ -73,6 +76,8 @@ public: SAW_FORBID_COPY(error_registry); SAW_FORBID_MOVE(error_registry); + error_or<const std::string_view> search_category(const error::code& id) const; + error_or<error::code> search_id(const std::string_view& desc) const; error_or<error::code> search_or_register_id(const std::string_view& desc, bool is_critical); @@ -131,7 +136,7 @@ struct critical { }; struct buffer_exhausted { - static constexpr std::string_view description = "Buffer is too small"; + static constexpr std::string_view description = "Buffer Exhausted"; static constexpr bool is_critical = false; }; |