-
-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation of the base error system for gp-engine #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
e82758b
add(forward): adding new forward declaration for the error system
mallory-scotton 46a29ca
add(error): adding new error record class to handle meta bag
mallory-scotton b33fe74
add(error): adding the implementation file for error record
mallory-scotton d84a3d4
add(errors): adding implementation for the sink base class
mallory-scotton 2aed702
fix: fixing pragma in cpp file
mallory-scotton 884f1a3
add(string): adding std::formatter overload for basic string view
mallory-scotton 7202339
add: adding basci string formatting
mallory-scotton c4e3ce0
add(error): adding implementation for record summary
mallory-scotton c956c52
add(errors): adding plaeholders files for the different sinks
mallory-scotton 7ac2eaf
add(container): adding new utility in basic string to implicitly convβ¦
mallory-scotton 107b21d
add(errors): adding error context and scoped context with additional β¦
mallory-scotton b21b8fe
add(errors): adding error registry to handle documentation linking
mallory-scotton 22c5030
add(main): adding temporary dump of all the errors
mallory-scotton b8bf7a5
update: updating naming of the config and severity file
mallory-scotton 2c40a7e
add(errors): adding error filters and predicate
mallory-scotton 6fd5dad
format: updating clang format rules about lambda indent
mallory-scotton b651138
add(vector): adding gp::eraseIf and gp::erase that mimics std::erase_if
mallory-scotton 7d12d8b
fix(error): fix error record to fallback to a dummy stacktrace if notβ¦
mallory-scotton ddfff1c
move(errors): move error sink out of the sinks
mallory-scotton cfef613
add(error): adding multi sink
mallory-scotton c8f79e5
add(error): adding main error system handler
mallory-scotton ed825ce
add(error): adding conveniance aliases to use error severity
mallory-scotton def987e
add(error) adding ability to raise error
mallory-scotton 8c728f7
add: adding test in the main for the GP_ macros to raise errors
mallory-scotton 25dd542
add: adding console sink for the error system
mallory-scotton d28013c
fix(errors): fixing banner not correctly showing that the stacktrace β¦
mallory-scotton 2397e8d
remove(errors): removing unfinished sinks
mallory-scotton a17f6a3
add(errors): adding abort sink
mallory-scotton 149692d
add(errors): adding breakpoint sink
mallory-scotton 5b2e904
fix(iwyu): fixing iwyu in console sink
mallory-scotton 7f73304
add(errors): adding file sink
mallory-scotton e91d335
add(forward): adding all classes to forward declarations of error
mallory-scotton 1aae11b
add(errors): adding base sink on initialization of error system
mallory-scotton 034b883
add: adding tests for the abort sink
mallory-scotton b0c4f97
fix: change constexpr config to inline
mallory-scotton 055afe3
fix: change ErrorRegistry describe/remediationHint/wikiUrl return typβ¦
Copilot f86cd8d
fix(errors): fixing a lot of issues with error subsystem
mallory-scotton 611a563
remove: removing expected since we are not using it right now
mallory-scotton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,96 @@ | ||
| // Copyright (c) - Graphical Playground. All rights reserved. | ||
| // For more information, see https://graphical-playground/legal | ||
| // mailto:support AT graphical-playground DOT com | ||
|
|
||
| #include "errors/ErrorContext.hpp" | ||
| #include "CoreMinimal.hpp" | ||
|
|
||
| namespace gp::error | ||
| { | ||
|
|
||
| void ErrorContext::push(gp::String subsystem, gp::String operation) | ||
| { | ||
| m_stack.pushBack({ std::move(subsystem), std::move(operation), {} }); | ||
| } | ||
|
|
||
| void ErrorContext::pop() noexcept | ||
| { | ||
| if (!m_stack.isEmpty()) | ||
| { | ||
| m_stack.popBack(); | ||
| } | ||
| } | ||
|
|
||
| void ErrorContext::tag(gp::String key, gp::String value) | ||
| { | ||
| if (!m_stack.isEmpty()) | ||
| { | ||
| m_stack.back().tags.pushBack({ std::move(key), std::move(value) }); | ||
| } | ||
| } | ||
|
|
||
| GP_NODISCARD bool ErrorContext::isEmpty() const noexcept | ||
| { | ||
| return m_stack.isEmpty(); | ||
| } | ||
|
|
||
| GP_NODISCARD gp::USize ErrorContext::depth() const noexcept | ||
| { | ||
| return m_stack.size(); | ||
| } | ||
|
|
||
| GP_NODISCARD const gp::Vector<ContextFrame>& ErrorContext::frames() const noexcept | ||
| { | ||
| return m_stack; | ||
| } | ||
|
|
||
| GP_NODISCARD gp::StringView ErrorContext::currentSubsystem() const noexcept | ||
| { | ||
| return m_stack.isEmpty() ? gp::StringView{} : m_stack.back().subsystem.asView(); | ||
| } | ||
|
|
||
| GP_NODISCARD MetaBag ErrorContext::flatten() const | ||
| { | ||
| MetaBag out; | ||
|
|
||
| for (gp::USize i = 0; i < m_stack.size(); ++i) | ||
| { | ||
| const auto& frame = m_stack[i]; | ||
| out.pushBack({ gp::String::format("scope[{}].subsystem", i), frame.subsystem }); | ||
| out.pushBack({ gp::String::format("scope[{}].operation", i), frame.operation }); | ||
| for (const auto& tag: frame.tags) | ||
| { | ||
| out.pushBack({ gp::String::format("scope[{}].{}", i, tag.key), tag.value }); | ||
| } | ||
| } | ||
|
|
||
| return out; | ||
| } | ||
|
|
||
| void ErrorContext::setThreadName(gp::String name) | ||
| { | ||
| m_threadName = std::move(name); | ||
| } | ||
|
|
||
| GP_NODISCARD const gp::String& ErrorContext::threadName() const noexcept | ||
| { | ||
| return m_threadName; | ||
| } | ||
|
|
||
| ContextScope::ContextScope(gp::String subsystem, gp::String operation) | ||
| { | ||
| ErrorContext::current().push(std::move(subsystem), std::move(operation)); | ||
| } | ||
|
|
||
| ContextScope::~ContextScope() noexcept | ||
| { | ||
| ErrorContext::current().pop(); | ||
| } | ||
|
|
||
| ContextScope& ContextScope::tag(gp::String key, gp::String value) | ||
| { | ||
| ErrorContext::current().tag(std::move(key), std::move(value)); | ||
| return *this; | ||
| } | ||
|
|
||
| } // namespace gp::error |
This file contains hidden or 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,133 @@ | ||
| // Copyright (c) - Graphical Playground. All rights reserved. | ||
| // For more information, see https://graphical-playground/legal | ||
| // mailto:support AT graphical-playground DOT com | ||
|
|
||
| #include "errors/ErrorRecord.hpp" | ||
| #include "errors/ErrorCode.hpp" | ||
| #include "errors/ErrorSeverity.hpp" | ||
| #include <ctime> | ||
| #include <functional> | ||
|
|
||
| namespace gp::error | ||
| { | ||
|
|
||
| void ErrorRecord::addMetadata(gp::String key, gp::String value) | ||
| { | ||
| metadata.pushBack({ std::move(key), std::move(value) }); | ||
| } | ||
|
|
||
| GP_NODISCARD gp::StringView ErrorRecord::getMetadata(gp::StringView key) const noexcept | ||
| { | ||
| for (const auto& entry: metadata) | ||
| { | ||
| if (entry.key == key) | ||
| { | ||
| return entry.value; | ||
| } | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| GP_NODISCARD bool ErrorRecord::hasCause() const noexcept | ||
| { | ||
| return cause != nullptr; | ||
| } | ||
|
|
||
| GP_NODISCARD gp::USize ErrorRecord::causeDepth() const noexcept | ||
| { | ||
| gp::USize depth = 0; | ||
| const ErrorRecord* current = cause.get(); | ||
| while (current) | ||
| { | ||
| ++depth; | ||
| current = current->cause.get(); | ||
| } | ||
| return depth; | ||
| } | ||
|
|
||
| GP_NODISCARD gp::String ErrorRecord::summary() const | ||
| { | ||
| return gp::String::format( | ||
| "[{}][{}:0x{:04X}] {} ({}:{})", | ||
| getSeverityName(severity), | ||
| getDomainName(code.domain()), | ||
| code.code(), | ||
| message, | ||
| location.file_name(), | ||
| location.line() | ||
| ); | ||
| } | ||
|
|
||
| GP_NODISCARD gp::String ErrorRecord::fullReport() const | ||
| { | ||
| gp::String out; | ||
| out.reserve(2048); | ||
|
|
||
| out += "βββ GP ErrorRecord ββββββββββββββββββββββββββββββββββββββββββββ\n"; | ||
| out += gp::String::format("β Severity : {}\n", getSeverityDisplay(severity)); | ||
| out += gp::String::format("β Code : [{}] 0x{:04X}\n", getDomainName(code.domain()), code.code()); | ||
| out += gp::String::format("β Message : {}\n", message); | ||
| out += gp::String::format( | ||
| "β Location : {}:{} in {}\n", location.file_name(), location.line(), location.function_name() | ||
| ); | ||
| out += gp::String::format( | ||
| "β Thread : {} ({})\n", | ||
| threadName.isEmpty() ? "unnamed" : threadName, | ||
| [&] | ||
| { | ||
| auto id = threadId; | ||
| std::hash<std::thread::id> hashThreadId; | ||
| return gp::String::format("{:#x}", hashThreadId(id)); | ||
| }() | ||
| ); | ||
|
|
||
| auto tt = std::chrono::system_clock::to_time_t(wallTime); | ||
| char tbuf[64]{}; | ||
| struct tm tm{}; | ||
| #if defined(_MSC_VER) | ||
| gmtime_s(&tm, &tt); | ||
| #else | ||
| gmtime_r(&tt, &tm); | ||
| #endif | ||
| strftime(tbuf, sizeof tbuf, "%Y-%m-%d %T UTC", &tm); | ||
| out += gp::String::format("β Timestamp : {}\n", tbuf); | ||
|
|
||
| if (!metadata.isEmpty()) | ||
| { | ||
| out += "β Meta :\n"; | ||
| for (const auto& m: metadata) | ||
| { | ||
| out += gp::String::format("β {} = {}\n", m.key, m.value); | ||
| } | ||
| } | ||
|
|
||
| #if GP_HAS_STACKTRACE | ||
| if (!stacktrace.empty()) | ||
| { | ||
| out += "β Stacktrace:\n"; | ||
| for (const auto& frame: stacktrace) | ||
| { | ||
| out += gp::String::format("β {}\n", std::to_string(frame)); | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| if (hasCause()) | ||
| { | ||
| out += "β Caused by :\n"; | ||
| const ErrorRecord* c = cause.get(); | ||
| int depth = 0; | ||
| while (c && depth < 8) | ||
| { | ||
| out += gp::String::format("β [{}] {}\n", getSeverityName(c->severity), c->message); | ||
| c = c->cause.get(); | ||
| ++depth; | ||
| } | ||
| } | ||
|
|
||
| out += "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n"; | ||
|
|
||
| return out; | ||
| } | ||
|
|
||
| } // namespace gp::error | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.