[ox/fs] Add oxPanic and remove ErrorInfo

This commit is contained in:
Gary Talent 2020-01-25 00:04:47 -06:00
parent c214f3334a
commit 52026ba1a3
4 changed files with 21 additions and 28 deletions

View File

@ -32,18 +32,22 @@ void assertFunc<bool>([[maybe_unused]]const char *file, [[maybe_unused]]int line
}
template<>
void assertFunc<Error>([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]Error err, [[maybe_unused]]const char *msg) {
#if defined(OX_USE_STDLIB)
void assertFunc<Error>(const char *file, int line, Error err, const char *msg) {
if (err) {
auto ei = ErrorInfo(err);
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << msg << '\n';
std::cerr << "\tError Code:\t" << ei.errCode << '\n';
if (ei.file != nullptr) {
std::cerr << "\tError Location:\t" << reinterpret_cast<const char*>(ei.file) << ':' << ei.line << '\n';
}
printStackTrace(2);
std::abort();
panic(file, line, err, msg);
}
}
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]Error err, [[maybe_unused]]const char *msg) {
#if defined(OX_USE_STDLIB)
std::cerr << "\033[31;1;1mPANIC:\033[0m (" << file << ':' << line << "): " << msg << '\n';
std::cerr << "\tError Code:\t" << err << '\n';
if (err.file != nullptr) {
std::cerr << "\tError Location:\t" << reinterpret_cast<const char*>(err.file) << ':' << err.line << '\n';
}
printStackTrace(2);
oxTrace("assert").del("") << "Failed assert: " << msg << " (" << file << ":" << line << ")";
std::abort();
#endif
}

View File

@ -23,10 +23,14 @@ void assertFunc<bool>(const char *file, int line, bool pass, const char *msg);
template<>
void assertFunc<Error>(const char *file, int line, Error err, const char*);
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]Error err, [[maybe_unused]]const char *msg);
}
#ifndef NDEBUG
#define oxAssert(pass, msg) ox::assertFunc<decltype(pass)>(__FILE__, __LINE__, pass, msg)
#define oxPanic(pass, msg) ox::panic(__FILE__, __LINE__, pass, msg)
#else
#define oxAssert(pass, msg)
#define oxPanic(pass, msg)
#endif

View File

@ -39,20 +39,6 @@ struct BaseError {
using Error = Integer<uint64_t, BaseError>;
struct ErrorInfo {
const char *file = nullptr;
int line = -1;
Error errCode = Error(0);
ErrorInfo() = default;
ErrorInfo(Error err) {
this->file = err.file;
this->line = err.line;
this->errCode = err;
}
};
static constexpr Error _error(const char *file, uint32_t line, Error errCode) {
Error err = errCode;
err.file = file;

View File

@ -61,11 +61,10 @@ StdOutStream::~StdOutStream() {
void logError(const char *file, int line, Error err) {
if (err) {
ErrorInfo ei(err);
TraceStream trc(file, line, "ox::error");
trc << "Error:" << ei.errCode;
if (ei.file != nullptr) {
trc << "(" << reinterpret_cast<const char*>(ei.file) << ":" << ei.line << ")";
trc << "Error:" << err;
if (err.file != nullptr) {
trc << "(" << reinterpret_cast<const char*>(err.file) << ":" << err.line << ")";
}
}
}