/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: ErrorStack.hpp Date: 2022-11-29 Author: Reece ***/ #pragma once namespace Aurora::Debug { struct ErrorStack; struct ErrorStackAccessor; struct ThreadMessage { AuSPtr pNextThreadMesage; AuSPtr pStringMessage; AuOptional eFailureCategory; AuOptional optStackTrace; AuOptional optOsErrorCode; AuUInt16 uDebugBuildSourceLineHint {}; AUKN_SYM const AuString &ToString(); }; /** * @brief An object to be used on the stack to log failures under the callframe * These errors include the SysPushErrorXXXX macros and out of memory conditions */ struct ErrorStack { AUKN_SYM ErrorStack(); AUKN_SYM ~ErrorStack(); inline bool HasCapturedMessage() { CheckErrors(); return bool(this->pHead); } inline bool HasCaptured() { return HasCapturedMessage() || this->bOutOfMemory; } inline bool HasMultipleOccurred() { return this->HasCaptured() && bool(this->pHead->pNextThreadMesage); } inline AuOptional ToStackTrace() { if (!this->HasCaptured()) { return {}; } if (!this->pHead->optStackTrace) { return {}; } return this->pHead->optStackTrace.value(); } inline AuOptional ToString() { static const AuString kOutOfMemoryString = "Aurora: Out of Memory"; if (this->HasCaptured()) { return this->pHead->ToString(); } else if (this->HasOOMCondition()) { return kOutOfMemoryString; } else { return {}; } } inline AuSPtr FirstMessage() { return this->pHead; } inline bool HasOOMCondition() { return this->bOutOfMemory; } protected: friend ErrorStackAccessor; AuSPtr pHead; ErrorStack *pNext {}; bool bOutOfMemory {}; }; } using AuErrorStack = Aurora::Debug::ErrorStack;