Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
result_types.h
Go to the documentation of this file.
1#pragma once
2
3// BSD 3-Clause License
4// Copyright (c) 2025, 🍀☀🌕🌥 🌊
5// See the LICENSE file in the project root for full license information.
6
7
20#include "error_codes.h"
21#include <kcenon/common/patterns/result.h>
22
23#include <optional>
24#include <string>
25
26namespace kcenon { namespace monitoring {
27
35struct error_info {
37 std::string message;
38 std::optional<std::string> context{std::nullopt};
39
41 const std::string& msg = "",
42 const std::optional<std::string>& ctx = std::nullopt)
43 : code(c)
44 , message(msg.empty() ? error_code_to_string(c) : msg)
45 , context(ctx) {}
46
51 std::string to_string() const {
52 std::string result = "[" + error_code_to_string(code) + "] " + message;
53 if (context.has_value()) {
54 result += " Context: " + context.value();
55 }
56 return result;
57 }
58
62 common::error_info to_common_error() const {
63 common::error_info info(static_cast<int>(code), message, "monitoring_system");
64 if (context) {
65 info.details = context;
66 }
67 return info;
68 }
69
73 static error_info from_common_error(const common::error_info& common_err) {
74 error_info info(static_cast<monitoring_error_code>(common_err.code),
75 common_err.message);
76 if (common_err.details) {
77 info.context = common_err.details;
78 }
79 return info;
80 }
81};
82
83} } // namespace kcenon::monitoring
Monitoring system specific error codes.
std::string error_code_to_string(monitoring_error_code code)
Convert error code to string representation.
monitoring_error_code
Comprehensive error codes for monitoring system operations.
Definition error_codes.h:25
@ info
Informational, no action required.
Extended error information with context.
static error_info from_common_error(const common::error_info &common_err)
Create from common_system error_info.
error_info(monitoring_error_code c, const std::string &msg="", const std::optional< std::string > &ctx=std::nullopt)
std::optional< std::string > context
common::error_info to_common_error() const
Convert to common_system error_info.
monitoring_error_code code
std::string to_string() const
Get formatted error string.