enh: support get origin string of taos errors
This commit is contained in:
parent
c2a80bd1cc
commit
95a6cbf8e0
|
@ -24,6 +24,12 @@ extern "C" {
|
|||
|
||||
// clang-format off
|
||||
|
||||
typedef struct {
|
||||
int32_t val;
|
||||
const char* str;
|
||||
const char* origin;
|
||||
} STaosError;
|
||||
|
||||
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
|
||||
|
||||
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
|
||||
|
@ -38,6 +44,7 @@ const char* terrstr();
|
|||
char* taosGetErrMsgReturn();
|
||||
char* taosGetErrMsg();
|
||||
int32_t* taosGetErrno();
|
||||
int32_t taosGetErrSize();
|
||||
#define terrno (*taosGetErrno())
|
||||
#define terrMsg (taosGetErrMsg())
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
|
||||
#define TAOS_ERROR_C
|
||||
|
||||
typedef struct {
|
||||
int32_t val;
|
||||
const char* str;
|
||||
} STaosError;
|
||||
// typedef struct {
|
||||
// int32_t val;
|
||||
// const char* str;
|
||||
// } STaosError;
|
||||
|
||||
static threadlocal int32_t tsErrno;
|
||||
static threadlocal char tsErrMsgDetail[ERR_MSG_LEN] = {0};
|
||||
|
@ -35,7 +35,9 @@ char* taosGetErrMsg() { return tsErrMsgDetail; }
|
|||
char* taosGetErrMsgReturn() { return tsErrMsgReturn; }
|
||||
|
||||
#ifdef TAOS_ERROR_C
|
||||
#define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str = (msg)},
|
||||
#define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str = (msg), .origin = #name},
|
||||
STaosError errors[] = {
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SUCCESS, "success")
|
||||
#else
|
||||
#define TAOS_DEFINE_ERROR(name, mod, code, msg) static const int32_t name = TAOS_DEF_ERROR_CODE(mod, code);
|
||||
#endif
|
||||
|
@ -44,11 +46,6 @@ char* taosGetErrMsgReturn() { return tsErrMsgReturn; }
|
|||
#define TAOS_SUCCEEDED(err) ((err) >= 0)
|
||||
#define TAOS_FAILED(err) ((err) < 0)
|
||||
|
||||
#ifdef TAOS_ERROR_C
|
||||
STaosError errors[] = {
|
||||
{.val = 0, .str = "success"},
|
||||
#endif
|
||||
|
||||
// rpc
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_UNAVAIL, "Unable to establish connection")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_FQDN_ERROR, "Unable to resolve FQDN")
|
||||
|
@ -784,7 +781,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDLITE_IVLD_OPEN_DIR, "Invalid TDLite open
|
|||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY, "Queue out of memory")
|
||||
|
||||
#ifdef TAOS_ERROR_C
|
||||
#if defined(TAOS_ERROR_INFO) || defined(TAOS_ERROR_C)
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -837,3 +834,5 @@ const char* tstrerror(int32_t err) {
|
|||
}
|
||||
|
||||
const char* terrstr() { return tstrerror(terrno); }
|
||||
|
||||
int32_t taosGetErrSize() { return sizeof(errors)/sizeof(errors[0]); }
|
||||
|
|
|
@ -123,4 +123,12 @@ add_test(
|
|||
#add_test(
|
||||
# NAME decompressTest
|
||||
# COMMAND decompressTest
|
||||
#)
|
||||
#)
|
||||
|
||||
# terrorTest
|
||||
add_executable(terrorTest "terrorTest.cpp")
|
||||
target_link_libraries(terrorTest os util common gtest_main)
|
||||
add_test(
|
||||
NAME terrorTest
|
||||
COMMAND terrorTest
|
||||
)
|
|
@ -0,0 +1,29 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
|
||||
#define TAOS_ERROR_INFO
|
||||
|
||||
#include <iostream>
|
||||
#include "os.h"
|
||||
#include "osTime.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
extern STaosError errors[];
|
||||
|
||||
using namespace std;
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
TEST(TAOS_ERROR_TEST, terror_test) {
|
||||
int32_t errSize = taosGetErrSize();
|
||||
for (int32_t i = 0; i < errSize; ++i) {
|
||||
STaosError *pInfo = &errors[i];
|
||||
std::cout << i + 1 << " " << pInfo->origin << " " << pInfo->val << std::endl;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue