#include "akerror.h" #include "err_capture.h" #include /* * akerr_init() registers a human-readable name for each library error code. * Verify the names are actually installed (mutation testing showed the * registration calls could be deleted without any test noticing). * * This list must stay exhaustive. AKERR_EOF, AKERR_ITERATOR_BREAK and * AKERR_NOT_IMPLEMENTED were previously valid codes with no registered name, so * they rendered as "Unknown Error" in every stack trace that carried them -- * the same class of silent gap that a too-small AKERR_MAX_ERR_VALUE used to * cause. The sweep below walks the whole AKERR_* offset span so a newly added * code without a name fails here rather than showing up in production traces. */ static const struct { int code; const char *name; } expected[] = { { AKERR_NULLPOINTER, "Null Pointer Error" }, { AKERR_OUTOFBOUNDS, "Out Of Bounds Error" }, { AKERR_API, "API Error" }, { AKERR_ATTRIBUTE, "Attribute Error" }, { AKERR_TYPE, "Type Error" }, { AKERR_KEY, "Key Error" }, { AKERR_INDEX, "Index Error" }, { AKERR_FORMAT, "Format Error" }, { AKERR_IO, "Input Output Error" }, { AKERR_VALUE, "Value Error" }, { AKERR_RELATIONSHIP, "Relationship Error" }, { AKERR_EOF, "End Of File" }, { AKERR_CIRCULAR_REFERENCE, "Circular Reference Error" }, { AKERR_ITERATOR_BREAK, "Iterator Break" }, { AKERR_NOT_IMPLEMENTED, "Not Implemented" }, { AKERR_BADEXC, "Invalid akerr_ErrorContext" }, }; int main(void) { akerr_init(); for ( unsigned i = 0; i < sizeof(expected) / sizeof(expected[0]); i++ ) { char *nm = akerr_name_for_status(expected[i].code, NULL); AKERR_CHECK(nm != NULL); AKERR_CHECK(strcmp(nm, expected[i].name) == 0); } /* * Every value in the library's own offset span must resolve to a real name. * AKERR_LAST_ERRNO_VALUE + 7 is the one deliberate hole (a removed code); * anything else nameless is a code someone added without registering it. */ for ( int offset = 1; offset <= AKERR_BADEXC - AKERR_LAST_ERRNO_VALUE; offset++ ) { int code = AKERR_LAST_ERRNO_VALUE + offset; char *nm = akerr_name_for_status(code, NULL); if ( offset == 7 ) { AKERR_CHECK(strcmp(nm, "Unknown Error") == 0); continue; } if ( strcmp(nm, "Unknown Error") == 0 || nm[0] == '\0' ) { fprintf(stderr, "AKERR_LAST_ERRNO_VALUE + %d (%d) has no name\n", offset, code); return 1; } } /* Every AKERR_* code must sit inside the band the library reserves. */ AKERR_CHECK(AKERR_BADEXC < AKERR_FIRST_CONSUMER_STATUS); fprintf(stderr, "err_error_names ok\n"); return 0; }