dmi_error_raise_ex

Synopsis

#include <opendmi/error.h>

bool dmi_error_raise_ex(dmi_context_t *context, dmi_error_code_t reason,
                        const char *message, ...);  /* macro */

Description

The dmi_error_raise_ex macro adds an error entry with reason code reason and an additional printf-style formatted message to the error queue of context. The source file name, function name, and line number are captured automatically from the call site.

The formatted message is stored in the message field of the resulting dmi_error_t entry and is freed automatically when the entry is evicted from the queue or the queue is cleared.

To raise an error without an additional message, use dmi_error_raise.

The error queue is a ring buffer with a maximum depth of DMI_ERROR_MAX_DEPTH entries. When the queue is full, the oldest entry is overwritten silently.

Parameters

context

DMI context.

reason

Error reason code.

message

printf-style format string for the additional message.

…​

Format arguments.

Return value

Returns true on success. Returns false if context is nullptr or if memory allocation for the formatted message fails. In the latter case the error is still added to the queue, left without a message.

Errors

None.

Examples

if (fd < 0) {
    dmi_error_raise_ex(context, DMI_ERROR_FILE_OPEN_FAILED,
                       "cannot open '%s': %s", path, strerror(errno));
    return false;
}