summaryrefslogtreecommitdiff
path: root/src/core/error.cpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2023-07-11 13:48:49 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2023-07-11 13:48:49 +0200
commitcc43bdd85f6425372623ebfee9cace98fd63e330 (patch)
tree500893c265e8198d9440f580be47a6206245f7aa /src/core/error.cpp
parent5ca077154f9e1a41618e301d64f0cc1661d06214 (diff)
c++,core: Added an error category get function
Diffstat (limited to 'src/core/error.cpp')
-rw-r--r--src/core/error.cpp19
1 files changed, 19 insertions, 0 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