FOSSredder 0.5.0
Loading...
Searching...
No Matches
ErrorReporting.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <exception>
9#include <string>
10#include <utility>
11
15
16namespace core::errors {
17
24 const ErrorEvent &event) {
25 if (reporter)
26 reporter->report(event);
27}
28
39 ErrorSeverity severity, const char *code,
40 const char *origin, std::string message,
41 ErrorContext context = {}) {
42 ErrorEvent event;
43 event.severity = severity;
44 event.code = code ? code : codes::GenericError;
45 event.origin = origin ? origin : std::string{};
46 event.message = std::move(message);
47 event.context = std::move(context);
48 report(reporter, event);
49}
50
59 ErrorSeverity severity, const char *origin,
60 std::exception_ptr exception) {
61 if (reporter)
62 reporter->reportException(severity, origin, exception);
63}
64
75 ErrorSeverity severity, const char *code,
76 const char *origin, std::exception_ptr exception,
77 ErrorContext context = {}) {
78 if (reporter)
79 reporter->report(makeExceptionEvent(severity, code, origin, exception,
80 std::move(context)));
81}
82
83} // namespace core::errors
Declares helpers for turning exceptions into structured error events.
Declares the structured diagnostics reporting port.
Port for reporting structured diagnostic error events.
virtual void reportException(core::errors::ErrorSeverity severity, const char *origin, std::exception_ptr exception)
Report an exception as a structured error event.
virtual void report(const core::errors::ErrorEvent &event)=0
Report a structured error event.
Defines shared structured error codes.
constexpr const char * GenericError
Fallback code for generic structured errors.
ErrorSeverity
Severity level for structured error events.
Definition ErrorEvent.h:17
std::vector< std::pair< std::string, std::string > > ErrorContext
Key/value context attached to an error event.
Definition ErrorEvent.h:27
void reportException(core::ports::diagnostics::IErrorReporter *reporter, ErrorSeverity severity, const char *origin, std::exception_ptr exception)
Report an exception through the reporter's default exception handling.
ErrorEvent makeExceptionEvent(ErrorSeverity severity, const char *code, const char *origin, std::exception_ptr exception, ErrorContext context={})
Build a structured event from an exception pointer.
void report(core::ports::diagnostics::IErrorReporter *reporter, const ErrorEvent &event)
Report an already constructed error event when a reporter exists.
Structured error payload sent through diagnostics ports.
Definition ErrorEvent.h:32