ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
asciichat_errno.h File Reference

⚠️‼️ Error and/or exit() when things go bad. More...

Go to the source code of this file.

Data Structures

struct  asciichat_error_context_t
 Error context structure. More...
 
struct  asciichat_error_stats_t
 Error statistics structure. More...
 

Macros

#define SET_ERRNO(code, context_msg, ...)
 Set error code with custom context message and log it.
 
#define SET_ERRNO_SYS(code, context_msg, ...)
 Set error code with custom message and system error context.
 
#define HAS_ERRNO(var)   asciichat_has_errno(var)
 Check if an error occurred and get full context.
 
#define CLEAR_ERRNO()   asciichat_clear_errno()
 Clear the current error state.
 
#define GET_ERRNO()   asciichat_get_errno()
 Get current error code (0 if no error)
 
#define PRINT_ERRNO_CONTEXT(context)   ((void)(context))
 
#define ASSERT_NO_ERRNO()   ((void)0)
 
#define PRINT_ERRNO_IF_ERROR()   ((void)0)
 
#define LOG_ERRNO_IF_SET(message)
 Check if any error occurred and log it if so.
 
#define LOG_ERRNO_IF_CODE(code, message)
 Check if a specific error occurred and log it if so.
 

Functions

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.
 
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_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)
 
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_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)
 
bool asciichat_has_errno (asciichat_error_context_t *context)
 Check if error occurred and get full context.
 
bool asciichat_has_wsa_error (void)
 Check if current error has WSA error code.
 
void asciichat_clear_errno (void)
 Clear the current error state.
 
asciichat_error_t asciichat_get_errno (void)
 Get current error code.
 
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_print_error_context (const asciichat_error_context_t *context)
 Print full error context to stderr.
 
void asciichat_error_stats_init (void)
 Initialize error statistics system.
 
void asciichat_error_stats_record (asciichat_error_t code)
 Record an error in statistics.
 
void asciichat_error_stats_print (void)
 Print error statistics to stderr.
 
void asciichat_error_stats_reset (void)
 Reset all error statistics to zero.
 
asciichat_error_stats_t asciichat_error_stats_get (void)
 Get current error statistics.
 
asciichat_error_t asciichat_get_thread_error (int thread_id)
 Get error code for a specific thread.
 
void asciichat_set_thread_error (int thread_id, asciichat_error_t code)
 Set error code for a specific thread.
 
void asciichat_clear_thread_error (int thread_id)
 Clear error code for a specific thread.
 
void asciichat_errno_suppress (bool suppress)
 Suppress error logging and reporting.
 
void asciichat_errno_cleanup (void)
 Cleanup error system resources.
 

Variables

__thread asciichat_error_context_t asciichat_errno_context
 Thread-local error context storage.
 
__thread asciichat_error_t asciichat_errno
 Thread-local current error code.
 

Detailed Description

⚠️‼️ Error and/or exit() when things go bad.

Definition in file asciichat_errno.h.

Macro Definition Documentation

◆ ASSERT_NO_ERRNO

#define ASSERT_NO_ERRNO ( )    ((void)0)

Definition at line 531 of file asciichat_errno.h.

◆ LOG_ERRNO_IF_CODE

#define LOG_ERRNO_IF_CODE (   code,
  message 
)
Value:
do { \
if (asciichat_errno == (code)) { \
asciichat_print_error_context(&asciichat_errno_context); \
} \
} while (0)
__thread asciichat_error_t asciichat_errno
Thread-local current error code.
__thread asciichat_error_context_t asciichat_errno_context
Thread-local error context storage.

Check if a specific error occurred and log it if so.

Parameters
codeError code to check for
messageCustom message to log

Usage in src/ code: if (asciichat_errno == ERROR_NETWORK) { LOG_ERRNO_IF_CODE(ERROR_NETWORK, "Network operation failed"); }

Definition at line 755 of file asciichat_errno.h.

756 { \
757 if (asciichat_errno == (code)) { \
758 asciichat_print_error_context(&asciichat_errno_context); \
759 } \
760 } while (0)

◆ LOG_ERRNO_IF_SET

#define LOG_ERRNO_IF_SET (   message)
Value:
do { \
asciichat_print_error_context(&asciichat_errno_context); \
} \
} while (0)
@ ASCIICHAT_OK
Definition error_codes.h:48

Check if any error occurred and log it if so.

Parameters
messageCustom message to log

Usage in src/ code: if (asciichat_errno != ASCIICHAT_OK) { LOG_ERRNO_IF_SET("Operation failed"); }

Definition at line 738 of file asciichat_errno.h.

739 { \
740 if (asciichat_errno != ASCIICHAT_OK) { \
741 asciichat_print_error_context(&asciichat_errno_context); \
742 } \
743 } while (0)

◆ PRINT_ERRNO_CONTEXT

#define PRINT_ERRNO_CONTEXT (   context)    ((void)(context))

Definition at line 530 of file asciichat_errno.h.

◆ PRINT_ERRNO_IF_ERROR

#define PRINT_ERRNO_IF_ERROR ( )    ((void)0)

Definition at line 532 of file asciichat_errno.h.