182#define SET_ERRNO(code, context_msg, ...) \
184 asciichat_set_errno_with_message(code, NULL, 0, NULL, context_msg, ##__VA_ARGS__); \
185 log_error("SET_ERRNO: " context_msg " (code: %d, meaning: %s)", ##__VA_ARGS__, code, \
186 asciichat_error_string(code)); \
190#define SET_ERRNO(code, context_msg, ...) \
192 asciichat_set_errno_with_message(code, __FILE__, __LINE__, __func__, context_msg, ##__VA_ARGS__); \
193 log_error("SET_ERRNO: " context_msg " (code: %d, meaning: %s)", ##__VA_ARGS__, code, \
194 asciichat_error_string(code)); \
211#define SET_ERRNO_SYS(code, context_msg, ...) \
213 int captured_errno = platform_get_last_error(); \
214 asciichat_set_errno_with_system_error_and_message(code, NULL, 0, NULL, captured_errno, context_msg, \
216 log_error("SETERRNO_SYS: " context_msg " (code: %d - %s, system error: %d - %s)", ##__VA_ARGS__, code, \
217 asciichat_error_string(code), captured_errno, platform_strerror(captured_errno)); \
221#define SET_ERRNO_SYS(code, context_msg, ...) \
223 int captured_errno = platform_get_last_error(); \
224 asciichat_set_errno_with_system_error_and_message(code, __FILE__, __LINE__, __func__, captured_errno, context_msg, \
226 log_error("SETERRNO_SYS: " context_msg " (code: %d - %s, system error: %d - %s)", ##__VA_ARGS__, code, \
227 asciichat_error_string(code), captured_errno, platform_strerror(captured_errno)); \
254#define HAS_ERRNO(var) asciichat_has_errno(var)
259#define CLEAR_ERRNO() asciichat_clear_errno()
264#define GET_ERRNO() asciichat_get_errno()
291 const char *context_message);
314 const char *format, ...);
360 const char *function,
int sys_errno,
const char *format, ...);
471 const char *format, ...);
496#if defined(DEBUG) || defined(ENABLE_ERRNO_BACKTRACES)
501#define PRINT_ERRNO_CONTEXT(context) asciichat_print_error_context(context)
506#define ASSERT_NO_ERRNO() \
508 asciichat_error_t err = asciichat_get_errno(); \
509 if (err != ASCIICHAT_OK) { \
510 asciichat_error_context_t ctx; \
511 asciichat_has_errno(&ctx); \
512 asciichat_print_error_context(&ctx); \
520#define PRINT_ERRNO_IF_ERROR() \
522 asciichat_error_context_t ctx; \
523 if (HAS_ERRNO(&ctx)) { \
524 asciichat_print_error_context(&ctx); \
530#define PRINT_ERRNO_CONTEXT(context) ((void)(context))
531#define ASSERT_NO_ERRNO() ((void)0)
532#define PRINT_ERRNO_IF_ERROR() ((void)0)
738#define LOG_ERRNO_IF_SET(message) \
740 if (asciichat_errno != ASCIICHAT_OK) { \
741 asciichat_print_error_context(&asciichat_errno_context); \
755#define LOG_ERRNO_IF_CODE(code, message) \
757 if (asciichat_errno == (code)) { \
758 asciichat_print_error_context(&asciichat_errno_context); \
unsigned long long uint64_t
void asciichat_set_errno(asciichat_error_t code, const char *file, int line, const char *function, const char *context_message)
Set error code with basic context.
bool asciichat_has_wsa_error(void)
Check if current error has WSA error code.
void asciichat_clear_thread_error(int thread_id)
Clear error code for a specific thread.
void asciichat_fatal_with_context(asciichat_error_t code, const char *file, int line, const char *function, const char *format,...)
Exit with error code and context (used by FATAL macro)
void asciichat_errno_suppress(bool suppress)
Suppress error logging and reporting.
void asciichat_set_errno_with_system_error(asciichat_error_t code, const char *file, int line, const char *function, int sys_errno)
Set error code with system error (errno)
__thread asciichat_error_t asciichat_errno
Thread-local current error code.
void asciichat_error_stats_print(void)
Print error statistics to stderr.
bool asciichat_has_errno(asciichat_error_context_t *context)
Check if error occurred and get full context.
void asciichat_clear_errno(void)
Clear the current error state.
asciichat_error_t asciichat_get_thread_error(int thread_id)
Get error code for a specific thread.
asciichat_error_t asciichat_get_errno(void)
Get current error code.
void asciichat_set_errno_with_wsa_error(asciichat_error_t code, const char *file, int line, const char *function, int wsa_error)
Set error code with Windows socket error (WSA error)
asciichat_error_stats_t asciichat_error_stats_get(void)
Get current error statistics.
void asciichat_error_stats_init(void)
Initialize error statistics system.
void asciichat_errno_cleanup(void)
Cleanup error system resources.
void asciichat_set_errno_with_message(asciichat_error_t code, const char *file, int line, const char *function, const char *format,...)
Set error code with formatted message.
void asciichat_error_stats_reset(void)
Reset all error statistics to zero.
__thread asciichat_error_context_t asciichat_errno_context
Thread-local error context storage.
void asciichat_set_thread_error(int thread_id, asciichat_error_t code)
Set error code for a specific thread.
void asciichat_print_error_context(const asciichat_error_context_t *context)
Print full error context to stderr.
void asciichat_set_errno_with_system_error_and_message(asciichat_error_t code, const char *file, int line, const char *function, int sys_errno, const char *format,...)
Set error code with system error and formatted message.
void asciichat_error_stats_record(asciichat_error_t code)
Record an error in statistics.
asciichat_error_t
Error and exit codes - unified status values (0-255)
📝 Logging API with multiple log levels and terminal output control
int wsa_error
Windows socket error code (if applicable, 0 otherwise)
int system_errno
System errno value (if applicable, 0 otherwise)
const char * function
Function name where error occurred (NULL in release builds)
char * context_message
Optional custom message (dynamically allocated, owned by system)
uint64_t timestamp
Timestamp when error occurred (microseconds since epoch)
char ** backtrace_symbols
Stack trace symbol strings (debug builds only)
bool has_system_error
True if system_errno is valid.
const char * file
Source file where error occurred (NULL in release builds)
int stack_depth
Number of stack frames captured (0 if not captured)
int line
Line number where error occurred (0 in release builds)
bool has_wsa_error
True if wsa_error is valid.
asciichat_error_t code
Error code (asciichat_error_t enum value)
Error statistics structure.
uint64_t last_error_time
Timestamp of last error (microseconds since epoch)
asciichat_error_t last_error_code
Error code of last error recorded.
uint64_t total_errors
Total number of errors recorded (sum of all error_counts)
Common SIMD utilities and structures.