Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/silk/util/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace silk
* failure that started the chain. All frame storage (headers + message bytes) lives in a single
* arena owned by the Error.
*
* Errors are normally produced through the RETURN_ERROR / CHECK_ERROR / CHECK_BOOL macros,
* Errors are normally produced through the SILK_RETURN_ERROR / SILK_CHECK_ERROR / SILK_CHECK_BOOL macros,
* which push a frame and capture the call-site file and line. Functions take an Error * error
* out-parameter and the caller declares the Error on its own stack:
*
Expand Down Expand Up @@ -139,10 +139,10 @@ class Error
* from a callee returning a code):
*
* if (input == nullptr) {
* RETURN_ERROR(EINVAL, error, "null input: idx=%d", idx);
* SILK_RETURN_ERROR(EINVAL, error, "null input: idx=%d", idx);
* }
*/
#define RETURN_ERROR(code, error, msg, ...) return (error)->push##__VA_OPT__(f)((code), __FILE__, __LINE__, msg __VA_OPT__(, ) __VA_ARGS__)
#define SILK_RETURN_ERROR(code, error, msg, ...) return (error)->push##__VA_OPT__(f)((code), __FILE__, __LINE__, msg __VA_OPT__(, ) __VA_ARGS__)

/**
* Failure propagation: if r is non-zero, push a new frame on top of *error and return r.
Expand All @@ -151,12 +151,12 @@ class Error
* see the class doc.
*
* int r = volume->allocateLsn(&lsn);
* CHECK_ERROR(r, error, "could not allocate LSN");
* SILK_CHECK_ERROR(r, error, "could not allocate LSN");
*
* int r = store->getRowBlockReference(rbn, time, rowFunctions, &reference, error);
* CHECK_ERROR(r, error, "could not get row-block reference: pgId=%u", rbn.pgId);
* SILK_CHECK_ERROR(r, error, "could not get row-block reference: pgId=%u", rbn.pgId);
*/
#define CHECK_ERROR(code, error, msg, ...) \
#define SILK_CHECK_ERROR(code, error, msg, ...) \
do \
{ \
if ((code) != 0) [[unlikely]] \
Expand All @@ -170,9 +170,9 @@ class Error
*
* NEVER embed a function call as cond -- capture into a bool b temp first:
* bool b = record.addRow(&context, recordRow);
* CHECK_BOOL(b, ENOSPC, error, "could not append row");
* SILK_CHECK_BOOL(b, ENOSPC, error, "could not append row");
*/
#define CHECK_BOOL(cond, code, error, msg, ...) \
#define SILK_CHECK_BOOL(cond, code, error, msg, ...) \
do \
{ \
if (!(cond)) [[unlikely]] \
Expand Down
12 changes: 6 additions & 6 deletions src/util/tests/error-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@ namespace
int returnLeaf(Error * error, int * macroLine)
{
*macroLine = __LINE__ + 1;
RETURN_ERROR(EIO, error, "disk failure");
SILK_RETURN_ERROR(EIO, error, "disk failure");
return 0;
}

int returnLeafFormatted(Error * error, int * macroLine)
{
*macroLine = __LINE__ + 1;
RETURN_ERROR(EIO, error, "could not open %s: errno=%d", "foo.txt", 42);
SILK_RETURN_ERROR(EIO, error, "could not open %s: errno=%d", "foo.txt", 42);
return 0;
}

int checkErrorPropagates(int innerCode, Error * error, int * macroLine)
{
int r = innerCode;
*macroLine = __LINE__ + 1;
CHECK_ERROR(r, error, "could not allocate LSN");
SILK_CHECK_ERROR(r, error, "could not allocate LSN");
return 0;
}

int checkErrorFormatted(int innerCode, Error * error, int * macroLine)
{
int r = innerCode;
*macroLine = __LINE__ + 1;
CHECK_ERROR(r, error, "could not insert record: pgId=%u", 7u);
SILK_CHECK_ERROR(r, error, "could not insert record: pgId=%u", 7u);
return 0;
}

int checkErrorStacks(Error * error, int * macroLine)
{
int r = error->push(EIO, "log.cpp", 11, "ring buffer full");
*macroLine = __LINE__ + 1;
CHECK_ERROR(r, error, "log write rejected at lsn=%lu", 42UL);
SILK_CHECK_ERROR(r, error, "log write rejected at lsn=%lu", 42UL);
return 0;
}

int checkBoolPropagates(bool cond, Error * error, int * macroLine)
{
*macroLine = __LINE__ + 1;
CHECK_BOOL(cond, ENOSPC, error, "could not append row");
SILK_CHECK_BOOL(cond, ENOSPC, error, "could not append row");
return 0;
}

Expand Down
Loading