From 34980502b35a9b672519e3daa6c4cf60c82d398b Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 8 Sep 2020 18:53:54 -0500 Subject: [PATCH] feat(error): add assertion and error related functions --- storm/Error.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ storm/Error.hpp | 28 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 storm/Error.cpp create mode 100644 storm/Error.hpp diff --git a/storm/Error.cpp b/storm/Error.cpp new file mode 100644 index 0000000..03d9a26 --- /dev/null +++ b/storm/Error.cpp @@ -0,0 +1,62 @@ +#include "Error.hpp" +#include +#include +#include + +void SErrDisplayAppFatal(const char* format, ...) { + va_list args; + va_start(args, format); + vprintf(format, args); + printf("\n"); + va_end(args); + + exit(EXIT_FAILURE); +} + +int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7) { + // TODO + + printf("\n=========================================================\n"); + + if (linenumber == -5) { + printf("Exception Raised!\n\n"); + + printf(" App: %s\n", "GenericBlizzardApp"); + + if (errorcode != 0x85100000) { + printf(" Error Code: 0x%08X\n", errorcode); + } + + // TODO output time + + printf(" Error: %s\n\n", description); + } else { + printf("Assertion Failed!\n\n"); + + printf(" App: %s\n", "GenericBlizzardApp"); + printf(" File: %s\n", filename); + printf(" Line: %d\n", linenumber); + + if (errorcode != 0x85100000) { + printf(" Error Code: 0x%08X\n", errorcode); + } + + // TODO output time + + printf(" Assertion: %s\n", description); + } + + if (recoverable) { + return 1; + } else { + exit(exitcode); + } +} + +void SErrPrepareAppFatal(const char* filename, int32_t linenumber) { + // TODO +} + +void SErrSetLastError(uint32_t errorcode) { + // TODO +} diff --git a/storm/Error.hpp b/storm/Error.hpp new file mode 100644 index 0000000..a9f6800 --- /dev/null +++ b/storm/Error.hpp @@ -0,0 +1,28 @@ +#ifndef STORM_ERROR_HPP +#define STORM_ERROR_HPP + +#include + +#if defined(NDEBUG) +#define STORM_ASSERT(x) \ + if (!(x)) { \ + SErrSetLastError(0x57); \ + return 0; \ + } +#else +#define STORM_ASSERT(x) \ + if (!(x)) { \ + SErrPrepareAppFatal(__FILE__, __LINE__); \ + SErrDisplayAppFatal(#x); \ + } +#endif + +void SErrDisplayAppFatal(const char* format, ...); + +int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7); + +void SErrPrepareAppFatal(const char* filename, int32_t linenumber); + +void SErrSetLastError(uint32_t errorcode); + +#endif