diff --git a/include/silk/util/error.h b/include/silk/util/error.h index 8cd16c3..a32bf25 100644 --- a/include/silk/util/error.h +++ b/include/silk/util/error.h @@ -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: * @@ -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. @@ -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]] \ @@ -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]] \ diff --git a/src/util/tests/error-test.cpp b/src/util/tests/error-test.cpp index 37ac6bb..44d65fb 100644 --- a/src/util/tests/error-test.cpp +++ b/src/util/tests/error-test.cpp @@ -15,14 +15,14 @@ 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; } @@ -30,7 +30,7 @@ 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; } @@ -38,7 +38,7 @@ 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; } @@ -46,14 +46,14 @@ 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; }