bio
 
Loading...
Searching...
No Matches
Error handling

GTK-inspired error handling. More...

Data Structures

struct  bio_error_t
 An error returned from a function. More...
 

Enumerations

enum  bio_core_error_code_t { BIO_NO_ERROR , BIO_ERROR_INVALID_ARGUMENT , BIO_ERROR_NOT_SUPPORTED }
 Core error codes. More...
 

Functions

static bool bio_has_error (bio_error_t *error)
 Convenient function to check whether an error was encountered.
 
static const char * bio_strerror (bio_error_t *error)
 Convenient function to format an error into a string.
 
static void bio_clear_error (bio_error_t *error)
 Convenient function to clear an error object.
 

Variables

const bio_tag_t BIO_CORE_ERROR
 A tag for core errors.
 

Detailed Description

GTK-inspired error handling.

By convention, functions in bio will take a bio_error_t when an error might happen:

bio_error_t error = { 0 };
if (!bio_fstat(file, &stat, &error)) {
BIO_ERROR("Error while stat-ing: " BIO_ERROR_FMT, BIO_ERROR_FMT_ARGS(&error));
}
bool bio_fstat(bio_file_t file, bio_stat_t *stat, bio_error_t *error)
Retrieves statistics about a file.
#define BIO_ERROR(...)
Log a message at BIO_LOG_LEVEL_ERROR level.
Definition bio.h:54
#define BIO_ERROR_FMT_ARGS(error)
Helper for logging a bio_error_t.
Definition bio.h:80
#define BIO_ERROR_FMT
Helper for logging a bio_error_t.
Definition bio.h:73
An error returned from a function.
Definition bio.h:468

It is valid to pass NULL to these functions when there is no interest for error details.

Enumeration Type Documentation

◆ bio_core_error_code_t

Core error codes.

Enumerator
BIO_NO_ERROR 

There is no error.

BIO_ERROR_INVALID_ARGUMENT 

An invalid argument was provided.

BIO_ERROR_NOT_SUPPORTED 

The operation is not supported.

Function Documentation

◆ bio_clear_error()

static void bio_clear_error ( bio_error_t error)
inlinestatic

Convenient function to clear an error object.

◆ bio_has_error()

static bool bio_has_error ( bio_error_t error)
inlinestatic

Convenient function to check whether an error was encountered.

◆ bio_strerror()

static const char * bio_strerror ( bio_error_t error)
inlinestatic

Convenient function to format an error into a string.

The returned buffer is managed by bio. It is guaranteed to be valid until another call to bio_strerror is made.

Remarks
The exact details are platform-dependent. However, a shared buffer is usually involved. This means the returned string should be immediately logged or copied before this function is called again.
See also
BIO_ERROR_FMT

Variable Documentation

◆ BIO_CORE_ERROR

const bio_tag_t BIO_CORE_ERROR
extern

A tag for core errors.

The error code will be one of the values in bio_core_error_code_t