2024-09-07 12:34:46 -04:00
|
|
|
#include "storm/error/Error.hpp"
|
2024-11-22 02:21:19 -05:00
|
|
|
#include "storm/Array.hpp"
|
2024-08-30 18:04:21 -04:00
|
|
|
|
|
|
|
|
#include <windows.h>
|
2023-08-17 02:02:23 -04:00
|
|
|
|
|
|
|
|
#include <cstdarg>
|
|
|
|
|
#include <cstdlib>
|
2024-11-22 02:21:19 -05:00
|
|
|
#include <cstdint>
|
2023-08-17 02:02:23 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
class error_report {
|
|
|
|
|
private:
|
|
|
|
|
TSGrowableArray<uint8_t> m_text;
|
|
|
|
|
uint32_t m_errorcode;
|
|
|
|
|
const char* m_filename;
|
|
|
|
|
int32_t m_linenumber;
|
|
|
|
|
const char* m_description;
|
|
|
|
|
int32_t m_recoverable;
|
|
|
|
|
|
|
|
|
|
void printf(const char *format, ...) {
|
|
|
|
|
constexpr size_t size = 1024;
|
|
|
|
|
char buf[size] = {0};
|
|
|
|
|
|
2024-11-22 02:44:17 -05:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
auto n = vsnprintf(buf, size, format, args);
|
2024-11-22 02:21:19 -05:00
|
|
|
va_end(args);
|
2024-11-22 02:44:17 -05:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
// Remove trailing zero
|
|
|
|
|
this->m_text.SetCount(this->m_text.Count()-1);
|
|
|
|
|
// Add formatted bytes plus trailing zero
|
|
|
|
|
this->m_text.Add(n+1, reinterpret_cast<uint8_t*>(buf));
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
error_report(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable) {
|
|
|
|
|
this->m_errorcode = errorcode;
|
|
|
|
|
this->m_filename = filename;
|
|
|
|
|
this->m_linenumber = linenumber;
|
|
|
|
|
this->m_description = description;
|
|
|
|
|
this->m_recoverable = recoverable;
|
|
|
|
|
}
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
void Format() {
|
|
|
|
|
this->printf("\n=========================================================\n");
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:47:26 -05:00
|
|
|
if (this->m_linenumber == -5) {
|
2024-11-22 02:21:19 -05:00
|
|
|
this->printf("Exception Raised!\n\n");
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
this->printf(" App: %s\n", "GenericBlizzardApp");
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:47:26 -05:00
|
|
|
if (this->m_errorcode != 0x85100000) {
|
2024-11-22 02:40:18 -05:00
|
|
|
this->printf(" Error Code: 0x%08X\n", this->m_errorcode);
|
2024-11-22 02:21:19 -05:00
|
|
|
}
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
// TODO output time
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:40:18 -05:00
|
|
|
this->printf(" Error: %s\n\n", this->m_description);
|
2024-11-22 02:21:19 -05:00
|
|
|
} else {
|
|
|
|
|
this->printf("Assertion Failed!\n\n");
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
this->printf(" App: %s\n", "GenericBlizzardApp");
|
2024-11-22 02:40:18 -05:00
|
|
|
this->printf(" File: %s\n", this->m_filename);
|
|
|
|
|
this->printf(" Line: %d\n", this->m_linenumber);
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:47:26 -05:00
|
|
|
if (this->m_errorcode != 0x85100000) {
|
|
|
|
|
this->printf(" Error Code: 0x%08X\n", this->m_errorcode);
|
2024-11-22 02:21:19 -05:00
|
|
|
}
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
// TODO output time
|
2024-11-22 02:47:26 -05:00
|
|
|
this->printf(" Assertion: %s\n", this->m_description);
|
2024-11-22 02:21:19 -05:00
|
|
|
}
|
2023-08-17 02:02:23 -04:00
|
|
|
}
|
|
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
void Display() {
|
|
|
|
|
// Output text to debugger
|
|
|
|
|
OutputDebugString(reinterpret_cast<LPCSTR>(this->m_text.Ptr()));
|
|
|
|
|
// Title
|
2024-11-22 02:49:19 -05:00
|
|
|
const char* caption = this->m_recoverable ? "Error" : "Unrecoverable error";
|
2024-11-22 02:21:19 -05:00
|
|
|
// Icon/type
|
|
|
|
|
UINT icon = this->m_recoverable ? MB_ICONWARNING : MB_ICONERROR;
|
|
|
|
|
MessageBox(nullptr, reinterpret_cast<LPCSTR>(this->m_text.Ptr()), caption, icon);
|
2023-08-17 02:02:23 -04:00
|
|
|
}
|
2024-11-22 02:21:19 -05:00
|
|
|
};
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7) {
|
|
|
|
|
error_report report(errorcode, filename, linenumber, description, recoverable);
|
2023-08-17 02:02:23 -04:00
|
|
|
|
2024-11-22 02:21:19 -05:00
|
|
|
// Format error string and write to debug console
|
|
|
|
|
report.Format();
|
|
|
|
|
// Show MessageBox (blocks until user response)
|
|
|
|
|
report.Display();
|
2023-08-17 02:02:23 -04:00
|
|
|
|
|
|
|
|
if (recoverable) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
exit(exitcode);
|
|
|
|
|
}
|
|
|
|
|
}
|