REFACTOR: Error handling

This commit is contained in:
2026-10-01 13:06:57 -04:00
parent b218af2952
commit 4bc6efd89e
13 changed files with 1333 additions and 794 deletions
+34 -10
View File
@@ -1,12 +1,36 @@
#include <stdio.h>
#include <utils/utils.h>
const char* error_messages[] = {
[ERR_ALLOC_FAIL] = "Calloc :- Failed to allocate",
[ERR_BUF_NULL] = "Buffer :- NULL",
[ERR_SIZE_ZERO] = "Size :- Size is or is less than 0 or invalid",
[ERR_VECTOR_NULL] = "Vector :- Given vector is null",
[ERR_MAX_PASSED] = "Max :- Vector Max value is overloaded",
[ERR_OUT_OF_BOUNDS] = "Bounds:- Value is out of bounds",
[ERR_NULL] = "Null:- Vector or buffer is null",
[ERR_DOUBLE_BUF] = "Buffer :- Both buffers are copies of each other",
};
const char*
vec_get_error_desc(ERROR_CODES err)
{
switch (err)
{
#define X(name, val, desc) \
case name: \
return desc;
ERROR_LIST(X)
#undef X
default:
"Unknown";
}
}
void
vec_print_errs(const unsigned int err)
{
if (err == SUCCESS)
{
printf("%s", vec_get_error_desc(SUCCESS));
return;
}
{
#define X(name, val, desc) \
if ((val) != 0 && ((err) & (val))) \
{ \
printf("%s\n", vec_get_error_desc(name)); \
}
ERROR_LIST(X)
#undef X
}
}