enh: support get macro string of taos errors

This commit is contained in:
kailixu 2024-06-13 06:57:13 +08:00
parent 95a6cbf8e0
commit 247183b6fc
3 changed files with 8 additions and 20 deletions

View File

@ -27,7 +27,7 @@ extern "C" {
typedef struct {
int32_t val;
const char* str;
const char* origin;
const char* macro;
} STaosError;
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))

View File

@ -21,11 +21,6 @@
#define TAOS_ERROR_C
// typedef struct {
// int32_t val;
// const char* str;
// } STaosError;
static threadlocal int32_t tsErrno;
static threadlocal char tsErrMsgDetail[ERR_MSG_LEN] = {0};
static threadlocal char tsErrMsgReturn[ERR_MSG_LEN] = {0};
@ -35,9 +30,7 @@ char* taosGetErrMsg() { return tsErrMsgDetail; }
char* taosGetErrMsgReturn() { return tsErrMsgReturn; }
#ifdef TAOS_ERROR_C
#define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str = (msg), .origin = #name},
STaosError errors[] = {
TAOS_DEFINE_ERROR(TSDB_CODE_SUCCESS, "success")
#define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str = (msg), .macro = #name},
#else
#define TAOS_DEFINE_ERROR(name, mod, code, msg) static const int32_t name = TAOS_DEF_ERROR_CODE(mod, code);
#endif
@ -46,6 +39,11 @@ STaosError errors[] = {
#define TAOS_SUCCEEDED(err) ((err) >= 0)
#define TAOS_FAILED(err) ((err) < 0)
#ifdef TAOS_ERROR_C
STaosError errors[] = {
TAOS_DEFINE_ERROR(TSDB_CODE_SUCCESS, "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")

View File

@ -4,26 +4,16 @@
#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;
std::cout << i + 1 << " " << pInfo->macro << " " << pInfo->val << std::endl;
}
}