AuroraRuntime/Include/Aurora/Debug/ErrorStack.hpp

106 lines
2.4 KiB
C++

/***
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<ThreadMessage> pNextThreadMesage;
AuSPtr<AuString> pStringMessage;
AuOptional<EFailureCategory> eFailureCategory;
AuOptional<StackTrace> optStackTrace;
AuOptional<AuUInt> 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<const StackTrace &> ToStackTrace()
{
if (!this->HasCaptured())
{
return {};
}
if (!this->pHead->optStackTrace)
{
return {};
}
return this->pHead->optStackTrace.value();
}
inline AuOptional<const AuString&> 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<ThreadMessage> FirstMessage()
{
return this->pHead;
}
inline bool HasOOMCondition()
{
return this->bOutOfMemory;
}
protected:
friend ErrorStackAccessor;
AuSPtr<ThreadMessage> pHead;
ErrorStack *pNext {};
bool bOutOfMemory {};
};
}
using AuErrorStack = Aurora::Debug::ErrorStack;