fix:move err msg to tmq interface

This commit is contained in:
wangmm0220 2024-04-19 16:36:11 +08:00
parent fe7bfc88c0
commit 16065e2a2d
4 changed files with 10 additions and 9 deletions

View File

@ -35,6 +35,7 @@ const char* terrstr();
#define ERR_MSG_LEN 256
char* taosGetErrMsgReturn();
char* taosGetErrMsg();
int32_t* taosGetErrno();
#define terrno (*taosGetErrno())

View File

@ -2182,7 +2182,12 @@ const char* tmq_err2str(int32_t err) {
} else if (err == -1) {
return "fail";
} else {
return tstrerror(err);
if(*(taosGetErrMsg()) == 0){
return tstrerror(err);
} else{
snprintf(taosGetErrMsgReturn(), ERR_MSG_LEN, "%s,detail:%s", tstrerror(err), taosGetErrMsg());
return (const char*)taosGetErrMsgReturn();
}
}
}

View File

@ -32,6 +32,7 @@ static threadlocal char tsErrMsgReturn[ERR_MSG_LEN] = {0};
int32_t* taosGetErrno() { return &tsErrno; }
char* taosGetErrMsg() { return tsErrMsgDetail; }
char* taosGetErrMsgReturn() { return tsErrMsgReturn; }
#ifdef TAOS_ERROR_C
#define TAOS_DEFINE_ERROR(name, msg) {.val = (name), .str = (msg)},
@ -796,13 +797,7 @@ const char* tstrerror(int32_t err) {
} else if (err < val) {
e = mid;
} else if (err == val) {
if(strlen(tsErrMsgDetail) == 0){
return errors[mid].str;
} else{
memset(tsErrMsgReturn, 0, ERR_MSG_LEN);
snprintf(tsErrMsgReturn, ERR_MSG_LEN, "%s,detail:%s", errors[mid].str, tsErrMsgDetail);
return (const char*)tsErrMsgReturn;
}
return errors[mid].str;
} else {
break;
}

View File

@ -1006,7 +1006,7 @@ void testDetailError(){
raw.raw_type = 2;
int32_t code = tmq_write_raw((TAOS *)1, raw);
ASSERT(code);
const char *err = taos_errstr(NULL);
const char *err = tmq_err2str(code);
char* tmp = strstr(err, "Invalid parameters,detail:taos:0x1 or data");
ASSERT(tmp != NULL);
}