载入中...
搜索中...
未找到
Diagnostic.h
浏览该文件的文档.
1#pragma once
2
8#include "common/Export.h"
9
10#include <cstdint>
11#include <iosfwd>
12#include <string>
13#include <string_view>
14#include <utility>
15#include <vector>
16
17namespace eve {
18
20enum class Severity : uint8_t {
21 Info,
22 Warning,
23 Error,
24 Fatal,
25};
26
28[[nodiscard]] constexpr std::string_view severityName(Severity severity) noexcept {
29 switch (severity) {
30 case Severity::Info: return "info";
31 case Severity::Warning: return "warning";
32 case Severity::Error: return "error";
33 case Severity::Fatal: return "fatal";
34 }
35 return "unknown";
36}
37
39EVENGINE_API_FOUNDATION std::ostream& operator<<(std::ostream& stream, Severity severity);
40
47enum class DiagnosticCode : uint32_t {
48 None = 0,
51 NotFound = 3,
52 AlreadyExists = 4,
53 Conflict = 5,
54 Unsupported = 6,
55 Cancelled = 7,
56 StaleHandle = 8,
57 ParseError = 9,
60 Failed = 12,
61 HashMismatch = 13,
62 UnknownVersion = 14,
63 CallbackFailure = 15,
75 TypeMismatch = 21,
76};
77
85using DiagnosticDetail = std::pair<std::string, std::string>;
86
88using DiagnosticDetails = std::vector<DiagnosticDetail>;
89
94class [[nodiscard("Diagnostic should be inspected or passed to a Result")]] EVENGINE_API_FOUNDATION Diagnostic {
95public:
97 Diagnostic() noexcept;
99 ~Diagnostic() noexcept;
101 Diagnostic(const Diagnostic& other);
103 Diagnostic(Diagnostic&& other) noexcept;
105 Diagnostic& operator=(const Diagnostic& other);
107 Diagnostic& operator=(Diagnostic&& other) noexcept;
108
116 Diagnostic(DiagnosticCode code, Severity severity, std::string message, std::string path = {});
117
128 Diagnostic(DiagnosticCode code, Severity severity, std::string message, std::string path, DiagnosticDetails details,
129 std::string source = {});
130
132 static Diagnostic error(DiagnosticCode code, std::string message, std::string path = {});
134 static Diagnostic error(DiagnosticCode code, std::string message, std::string path, DiagnosticDetails details,
135 std::string source = {});
137 static Diagnostic warning(DiagnosticCode code, std::string message, std::string path = {});
139 static Diagnostic warning(DiagnosticCode code, std::string message, std::string path, DiagnosticDetails details,
140 std::string source = {});
141
143 DiagnosticCode code() const noexcept { return code_; }
145 Severity severity() const noexcept { return severity_; }
147 const std::string& message() const noexcept { return message_; }
149 const std::string& path() const noexcept { return path_; }
151 const DiagnosticDetails& details() const noexcept { return details_; }
153 const std::string& source() const noexcept { return source_; }
154
156 void addDetail(std::string key, std::string value);
157
159 bool isError() const noexcept { return severity_ == Severity::Error || severity_ == Severity::Fatal; }
160
161private:
162 DiagnosticCode code_ = DiagnosticCode::None;
163 Severity severity_ = Severity::Info;
164 std::string message_;
165 std::string path_;
166 DiagnosticDetails details_;
167 std::string source_;
168};
169
176[[nodiscard]] constexpr std::string_view diagnosticCodeName(DiagnosticCode code) noexcept {
177 switch (code) {
178 case DiagnosticCode::None: return "none";
179 case DiagnosticCode::InvalidArgument: return "invalid_argument";
180 case DiagnosticCode::PreconditionViolation: return "precondition_violation";
181 case DiagnosticCode::NotFound: return "not_found";
182 case DiagnosticCode::AlreadyExists: return "already_exists";
183 case DiagnosticCode::Conflict: return "conflict";
184 case DiagnosticCode::Unsupported: return "unsupported";
185 case DiagnosticCode::Cancelled: return "cancelled";
186 case DiagnosticCode::StaleHandle: return "stale_handle";
187 case DiagnosticCode::ParseError: return "parse_error";
188 case DiagnosticCode::SerializationError: return "serialization_error";
189 case DiagnosticCode::InvariantViolation: return "invariant_violation";
190 case DiagnosticCode::Failed: return "failed";
191 case DiagnosticCode::HashMismatch: return "hash_mismatch";
192 case DiagnosticCode::UnknownVersion: return "unknown_version";
193 case DiagnosticCode::CallbackFailure: return "callback_failure";
194 case DiagnosticCode::DialogueNotWaitingForChoice: return "dialogue_not_waiting_for_choice";
195 case DiagnosticCode::DialogueNotWaitingForCommand: return "dialogue_not_waiting_for_command";
196 case DiagnosticCode::DialogueConditionRejected: return "dialogue_condition_rejected";
197 case DiagnosticCode::DialogueRouteNotFound: return "dialogue_route_not_found";
198 case DiagnosticCode::ProcgenGroupDataInvalid: return "procgen_group_data_invalid";
199 case DiagnosticCode::TypeMismatch: return "type_mismatch";
200 }
201 return "unknown";
202}
203
205EVENGINE_API_FOUNDATION std::ostream& operator<<(std::ostream& stream, DiagnosticCode code);
206
207} // namespace eve
208
209
210// Every sequence keeps its own allocation and Diagnostic elements. Cross-group
211// Windows consumers share only the non-template operations; all participants
212// use the same CRT and iterator-debug configuration. Foundation, static and
213// non-Windows consumers retain the standard-library bodies.
214#if defined(_WIN32) && defined(EVENGINE_MODULE_DLL) && !defined(EVENGINE_EXPORTS_FOUNDATION)
215extern template class __declspec(dllimport) std::vector<eve::Diagnostic>;
216#endif
SQObjectPtr key
Definition ECS.cpp:155
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string message
DiagnosticCode code
std::string error
Definition Package.cpp:174
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
std::string_view source
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
DiagnosticCode code() const noexcept
Stable machine-readable code.
Definition Diagnostic.h:143
const std::string & path() const noexcept
Optional field, property, URI, or logical path.
Definition Diagnostic.h:149
bool isError() const noexcept
Whether the diagnostic represents an error or fatal condition.
Definition Diagnostic.h:159
Severity severity() const noexcept
Severity for logging and presentation.
Definition Diagnostic.h:145
Diagnostic() noexcept
Construct an empty informational diagnostic.
const std::string & message() const noexcept
Human-readable explanation.
Definition Diagnostic.h:147
const DiagnosticDetails & details() const noexcept
Structured context in insertion order.
Definition Diagnostic.h:151
const std::string & source() const noexcept
Optional producer or subsystem that emitted the diagnostic.
Definition Diagnostic.h:153
eve::Diagnostic Diagnostic
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
std::vector< DiagnosticDetail > DiagnosticDetails
Owning collection of diagnostic details with stable insertion order.
Definition Diagnostic.h:88
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
@ ProcgenGroupDataInvalid
Mesh group sidecar data is inconsistent with its dense streams.
@ TypeMismatch
A stable reference resolved to a different canonical domain type.
@ DialogueRouteNotFound
A requested dialogue route does not exist on the current node.
@ DialogueNotWaitingForChoice
Dialogue runner is not positioned at a choice suspension point.
@ DialogueConditionRejected
A dialogue condition rejected the requested route.
@ DialogueNotWaitingForCommand
Dialogue runner is not positioned at an asynchronous command.
std::ostream & operator<<(std::ostream &stream, Severity severity)
Writes a severity for diagnostics and test output.
Definition Diagnostic.cpp:7
constexpr std::string_view severityName(Severity severity) noexcept
Returns the stable lowercase severity spelling.
Definition Diagnostic.h:28
std::pair< std::string, std::string > DiagnosticDetail
A structured detail attached to a Diagnostic.
Definition Diagnostic.h:85
Severity
Stable severity of a diagnostic, independent of its display text.
Definition Diagnostic.h:20
constexpr std::string_view diagnosticCodeName(DiagnosticCode code) noexcept
Return a stable, compact spelling useful for logs and diagnostics.
Definition Diagnostic.h:176