Commit 7bd2df58 authored by Matthieu Dorier's avatar Matthieu Dorier

better error management

parent ee5dd535
......@@ -22,48 +22,59 @@ typedef uint64_t sdskv_database_id_t;
#define SDSKV_KEEP_ORIGINAL 0 /* for migration operations, keep original */
#define SDSKV_REMOVE_ORIGINAL 1 /* for migration operations, remove the origin after migrating */
/* Note: the values below are used in sdskv-common.hpp, do not change them! */
#define SDSKV_SUCCESS 0 /* Success */
#define SDSKV_ERR_ALLOCATION -1 /* Error allocating something */
#define SDSKV_ERR_INVALID_ARG -2 /* An argument is invalid */
#define SDSKV_ERR_MERCURY -3 /* An error happened calling a Mercury function */
#define SDSKV_ERR_DB_CREATE -4 /* Could not create database */
#define SDSKV_ERR_DB_NAME -5 /* Invalid database name */
#define SDSKV_ERR_UNKNOWN_DB -6 /* Database refered to by id is not known to provider */
#define SDSKV_ERR_UNKNOWN_PR -7 /* Mplex id could not be matched with a provider */
#define SDSKV_ERR_PUT -8 /* Could not put into the database */
#define SDSKV_ERR_UNKNOWN_KEY -9 /* Key requested does not exist */
#define SDSKV_ERR_SIZE -10 /* Client did not allocate enough for the requested data */
#define SDSKV_ERR_ERASE -11 /* Could not erase the given key */
#define SDSKV_ERR_MIGRATION -12 /* Error during data migration */
#define SDSKV_OP_NOT_IMPL -13 /* Operation not implemented for this backend */
#define SDSKV_ERR_COMP_FUNC -14 /* Comparison function does not exist */
#define SDSKV_ERR_REMI -15 /* REMI-related error */
#define SDSKV_ERR_ARGOBOTS -16 /* Argobots related error */
#define SDSKV_ERR_KEYEXISTS -17 /* Put operation would override data */
#define SDSKV_ERR_END -18 /* End of range for valid error codes */
/* Errors in SDSKV are int32_t. The most-significant byte stores the Argobots error, if any.
* The second most-significant byte stores the Mercury error, if any. The next 2 bytes store
* the SDSKV error code defined bellow. Argobots and Mercury errors should be built using
* SDSKV_MAKE_HG_ERROR and SDSKV_MAKE_ABT_ERROR. */
#define SDSKV_RETURN_VALUES \
X(SDSKV_SUCCESS, "Success") \
X(SDSKV_ERR_ALLOCATION, "Allocation error") \
X(SDSKV_ERR_INVALID_ARG, "Invalid argument") \
X(SDSKV_ERR_PR_EXISTS, "Provide id already used") \
X(SDSKV_ERR_DB_CREATE, "Could not create database") \
X(SDSKV_ERR_DB_NAME, "Invalid database name") \
X(SDSKV_ERR_UNKNOWN_DB, "Invalid database id") \
X(SDSKV_ERR_UNKNOWN_PR, "Invalid provider id") \
X(SDSKV_ERR_PUT, "Error writing in the database") \
X(SDSKV_ERR_UNKNOWN_KEY, "Unknown key") \
X(SDSKV_ERR_SIZE, "Provided buffer size too small") \
X(SDSKV_ERR_ERASE, "Error erasing from the database" ) \
X(SDSKV_ERR_MIGRATION, "Migration error") \
X(SDSKV_OP_NOT_IMPL, "Function not implemented") \
X(SDSKV_ERR_COMP_FUNC, "Invalid comparison function") \
X(SDSKV_ERR_REMI, "REMI error") \
X(SDSKV_ERR_KEYEXISTS, "Key exists") \
X(SDSKV_ERR_MAX, "End of range for valid error codes")
#define X(__err__, __msg__) __err__,
typedef enum { SDSKV_RETURN_VALUES } sdskv_return_t;
#undef X
static const char* const sdskv_error_messages[] = {
"",
"Allocation error",
"Invalid argument",
"Mercury error",
"Could not create database",
"Invalid database name",
"Invalid database id",
"Invalid provider id",
"Error writing in the database",
"Unknown key",
"Provided buffer size too small",
"Error erasing from the database",
"Migration error",
"Function not implemented",
"Invalid comparison function",
"REMI error",
"Argobots error",
"Key exists"
#define X(__err__, __msg__) __msg__,
SDSKV_RETURN_VALUES
#undef X
};
#define SDSKV_MAKE_HG_ERROR(__hg_err__) \
(((int32_t)(__hg_err__)) << 24)
#define SDSKV_MAKE_ABT_ERROR(__abt_err__) \
(((int32_t)(__abt_err__)) << 16)
#define SDSKV_GET_HG_ERROR(__err__) \
(((__err__) & (0b11111111 << 24)) >> 24)
#define SDSKV_GET_ABT_ERROR(__err__) \
(((__err__) & (0b11111111 << 16)) >> 16)
#define SDSKV_ERROR_IS_HG(__err__) \
((__err__) & (0b11111111 << 24))
#define SDSKV_ERROR_IS_ABT(__err__) \
((__err__) & (0b11111111 << 16))
#if defined(__cplusplus)
}
#endif
......
......@@ -17,8 +17,12 @@ class exception : public std::exception {
exception(int error)
: m_error(error) {
if(error < 0 && error > SDSKV_ERR_END) {
m_msg = std::string("[SDSKV] ") + sdskv_error_messages[-error];
if(error > 0 && error < SDSKV_ERR_MAX) {
m_msg = std::string("[SDSKV] ") + sdskv_error_messages[error];
} else if(SDSKV_ERROR_IS_HG(error)) {
m_msg = std::string("[SDSKV] Mercury error ") + std::to_string(SDSKV_GET_HG_ERROR(error));
} else if(SDSKV_ERROR_IS_ABT(error)) {
m_msg = std::string("[SDSKV] Argobots error ") + std::to_string(SDSKV_GET_ABT_ERROR(error));
} else {
m_msg = std::string("[SDSKV] Unknown error code ") + std::to_string(error);
}
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment