nostalgia/deps/ox/src/ox/std/assert.cpp

41 lines
1.1 KiB
C++

/*
* Copyright 2015 - 2022 gary@drinkingtea.net
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#if defined(OX_USE_STDLIB)
#include <iostream>
#endif
#include "stacktrace.hpp"
#include "trace.hpp"
#include "assert.hpp"
namespace ox {
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *panicMsg, [[maybe_unused]]const Error &err) noexcept {
#ifdef OX_USE_STDLIB
if (!std::is_constant_evaluated()) {
std::cerr << "\033[31;1;1mPANIC:\033[0m (" << file << ':' << line << "): " << panicMsg << '\n';
if (err.msg) {
std::cerr << "\tError Message:\t" << err.msg << '\n';
}
std::cerr << "\tError Code:\t" << err << '\n';
if (err.file != nullptr) {
std::cerr << "\tError Location:\t" << err.file << ':' << err.line << '\n';
}
printStackTrace(2);
oxTrace("panic").del("") << "Panic: " << panicMsg << " (" << file << ":" << line << ")";
std::abort();
} else {
assert(false);
}
#endif
}
}