AuroraRuntime/Include/Aurora/Debug/ErrorStack.hpp

102 lines
2.2 KiB
C++
Raw Normal View History

/***
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 {};
2024-02-14 00:32:30 +00:00
AUKN_SYM const AuString &ToString();
};
struct ErrorStack
{
2023-03-22 18:11:32 +00:00
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 {};
}
2024-02-14 00:32:30 +00:00
return this->pHead->optStackTrace.value();
}
2024-02-14 00:32:30 +00:00
inline AuOptional<const AuString&> ToString()
{
2024-02-14 00:32:30 +00:00
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;
}
2024-02-14 00:32:30 +00:00
inline bool HasOOMCondition()
{
return this->bOutOfMemory;
}
protected:
2024-02-14 00:32:30 +00:00
friend ErrorStackAccessor;
AuSPtr<ThreadMessage> pHead;
ErrorStack *pNext {};
2024-02-14 00:32:30 +00:00
bool bOutOfMemory {};
};
}
using AuErrorStack = Aurora::Debug::ErrorStack;