-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Error Handling functionality
* subscribe error * raise error * request clear error Signed-off-by: Andreas Heinrich <andreas.heinrich@rwth-aachen.de>
- Loading branch information
Showing
17 changed files
with
816 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest | ||
#ifndef UTILS_ERROR_HPP | ||
#define UTILS_ERROR_HPP | ||
|
||
#include <filesystem> | ||
#include <fmt/format.h> | ||
#include <map> | ||
#include <string> | ||
|
||
#include <utils/date.hpp> | ||
#include <utils/types.hpp> | ||
|
||
namespace Everest { | ||
namespace error { | ||
|
||
class NotValidErrorType : public std::exception { | ||
public: | ||
explicit NotValidErrorType(const std::string& error_type_) : error_type(error_type_){}; | ||
virtual const char* what() const throw() { | ||
return fmt::format("Error type '{}' is not valid.", error_type).c_str(); | ||
} | ||
|
||
private: | ||
const std::string error_type; | ||
}; | ||
|
||
enum class Severity { | ||
Low, | ||
Mid, | ||
High | ||
}; | ||
|
||
std::string severity_to_string(const Severity& s); | ||
Severity string_to_severity(const std::string& s); | ||
|
||
struct UUID { | ||
UUID(); | ||
UUID(const std::string& uuid); | ||
bool operator<(const UUID& other) const; | ||
|
||
std::string uuid; | ||
}; | ||
|
||
using ErrorHandle = UUID; | ||
struct Error { | ||
using time_point = date::utc_clock::time_point; | ||
Error(const std::string& type, const std::string& message, const std::string& description, | ||
const ImplementationIdentifier& from, const bool persistent, const Severity& severity, | ||
const time_point& timestamp, const UUID& uuid); | ||
Error(const std::string& type, const std::string& message, const std::string& description, | ||
const ImplementationIdentifier& from, const Severity& severity = Severity::Low); | ||
Error(const std::string& type, const std::string& message, const std::string& description, | ||
const std::string& from_module, const std::string& from_implementation, | ||
const Severity& severity = Severity::Low); | ||
|
||
std::string type; | ||
std::string description; | ||
std::string message; | ||
bool persistent; | ||
Severity severity; | ||
ImplementationIdentifier from; | ||
time_point timestamp; | ||
UUID uuid; | ||
}; | ||
|
||
class ErrorTypeMap { | ||
public: | ||
ErrorTypeMap() = default; | ||
ErrorTypeMap(std::filesystem::path error_types_dir); | ||
void load_error_types(std::filesystem::path error_types_dir); | ||
std::string get_description(const std::string& error_type) const; | ||
bool has(const std::string& error_type) const; | ||
|
||
private: | ||
std::map<std::string, std::string> error_types; | ||
}; | ||
|
||
using ErrorCallback = std::function<void(Error)>; | ||
|
||
} // namespace error | ||
} // namespace Everest | ||
|
||
#endif // UTILS_ERROR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest | ||
#ifndef UTILS_ERROR_JSON_HPP | ||
#define UTILS_ERROR_JSON_HPP | ||
|
||
#include <utils/error.hpp> | ||
|
||
namespace Everest { | ||
namespace error { | ||
|
||
Error json_to_error(const json& j); | ||
json error_to_json(const Error& e); | ||
|
||
} // namespace error | ||
} // namespace Everest | ||
|
||
#endif // UTILS_ERROR_JSON_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.