fix:[TD-31696]print error log to screen if init error

This commit is contained in:
wangmm0220 2024-08-30 10:04:01 +08:00
parent c7776e9dac
commit 35f83bd70a
2 changed files with 25 additions and 23 deletions

View File

@ -485,27 +485,27 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input
}
if ((code = cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl)) != 0) {
uError("failed to load from apollo url:%s since %s", apolloUrl, tstrerror(code));
printf("failed to load from apollo url:%s since %s\n", apolloUrl, tstrerror(code));
TAOS_RETURN(code);
}
if ((code = cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile)) != 0) {
uError("failed to load from cfg file:%s since %s", cfgFile, tstrerror(code));
printf("failed to load from cfg file:%s since %s\n", cfgFile, tstrerror(code));
TAOS_RETURN(code);
}
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile)) != 0) {
uError("failed to load from env file:%s since %s", envFile, tstrerror(code));
printf("failed to load from env file:%s since %s\n", envFile, tstrerror(code));
TAOS_RETURN(code);
}
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL)) != 0) {
uError("failed to load from global env variables since %s", tstrerror(code));
printf("failed to load from global env variables since %s\n", tstrerror(code));
TAOS_RETURN(code);
}
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd)) != 0) {
uError("failed to load from cmd env variables since %s", tstrerror(code));
printf("failed to load from cmd env variables since %s\n", tstrerror(code));
TAOS_RETURN(code);
}
@ -1769,14 +1769,14 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
TAOS_CHECK_GOTO(taosAddSystemCfg(tsCfg), &lino, _exit);
if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
uError("failed to load cfg since %s", tstrerror(code));
printf("failed to load cfg since %s\n", tstrerror(code));
cfgCleanup(tsCfg);
tsCfg = NULL;
TAOS_RETURN(code);
}
if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) {
uError("failed to load cfg from array since %s", tstrerror(code));
printf("failed to load cfg from array since %s\n", tstrerror(code));
cfgCleanup(tsCfg);
tsCfg = NULL;
TAOS_RETURN(code);
@ -1798,7 +1798,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
SConfigItem *pItem = cfgGetItem(tsCfg, "debugFlag");
if (NULL == pItem) {
uError("debugFlag not found in cfg");
printf("debugFlag not found in cfg\n");
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
}
TAOS_CHECK_GOTO(taosSetAllDebugFlag(tsCfg, pItem->i32), &lino, _exit);
@ -1811,7 +1811,7 @@ _exit:
if (TSDB_CODE_SUCCESS != code) {
cfgCleanup(tsCfg);
tsCfg = NULL;
uError("failed to init cfg at %d since %s", lino, tstrerror(code));
printf("failed to init cfg at %d since %s\n", lino, tstrerror(code));
}
TAOS_RETURN(code);

View File

@ -383,10 +383,6 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
(void)taosThreadMutexUnlock(&pCfg->lock);
}
if (code != 0){
printf("cfg:%s, type:%s src:%s value:%s failed since %s\n", pItem->name, cfgDtypeStr(pItem->dtype),
cfgStypeStr(stype), value, tstrerror(code));
}
TAOS_RETURN(code);
}
@ -998,7 +994,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
const char *filepath = ".env";
if (envFile != NULL && strlen(envFile) > 0) {
if (!taosCheckExistFile(envFile)) {
uError("failed to load env file:%s", envFile);
printf("failed to load env file:%s\n", envFile);
TAOS_RETURN(TSDB_CODE_NOT_FOUND);
}
filepath = envFile;
@ -1073,7 +1069,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code));
TAOS_RETURN(TSDB_CODE_SUCCESS);
} else {
uError("failed to load from cfg file %s since %s", filepath, tstrerror(code));
printf("failed to load from cfg file %s since %s\n", filepath, tstrerror(code));
TAOS_RETURN(code);
}
}
@ -1115,6 +1111,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
}
code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true);
if (code != 0){
printf("cfg:%s, value:%s failed since %s\n", name,newValue, tstrerror(code));
}
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
} else {
(void)paGetToken(value + vlen + 1, &value2, &vlen2);
@ -1129,6 +1128,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
}
code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE, true);
if (code != 0){
printf("cfg:%s, value:%s failed since %s\n", name, value, tstrerror(code));
}
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
}
@ -1152,7 +1154,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
uInfo("load from cfg file %s success", filepath);
TAOS_RETURN(TSDB_CODE_SUCCESS);
} else {
uError("failed to load from cfg file %s since %s", filepath, tstrerror(code));
printf("failed to load from cfg file %s since %s\n", filepath, tstrerror(code));
TAOS_RETURN(code);
}
}
@ -1234,7 +1236,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
char *p = strchr(url, ':');
if (p == NULL) {
uError("fail to load apoll url: %s, unknown format", url);
printf("fail to load apoll url: %s, unknown format\n", url);
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
}
p++;
@ -1242,7 +1244,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (strncmp(url, "jsonFile", 8) == 0) {
char *filepath = p;
if (!taosCheckExistFile(filepath)) {
uError("failed to load json file:%s", filepath);
printf("failed to load json file:%s\n", filepath);
TAOS_RETURN(TSDB_CODE_NOT_FOUND);
}
@ -1254,7 +1256,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
char *buf = taosMemoryMalloc(fileSize + 1);
if (!buf) {
(void)taosCloseFile(&pFile);
uError("load json file error: %s, failed to alloc memory", filepath);
printf("load json file error: %s, failed to alloc memory\n", filepath);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
@ -1262,7 +1264,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
(void)taosLSeekFile(pFile, 0, SEEK_SET);
if (taosReadFile(pFile, buf, fileSize) <= 0) {
(void)taosCloseFile(&pFile);
uError("load json file error: %s", filepath);
printf("load json file error: %s\n", filepath);
taosMemoryFreeClear(buf);
TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT);
}
@ -1271,7 +1273,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (NULL == pJson) {
const char *jsonParseError = tjsonGetError();
if (jsonParseError != NULL) {
uError("load json file parse error: %s", jsonParseError);
printf("load json file parse error: %s\n", jsonParseError);
}
taosMemoryFreeClear(buf);
TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT);
@ -1339,7 +1341,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
// } else if (strncmp(url, "jsonUrl", 7) == 0) {
// } else if (strncmp(url, "etcdUrl", 7) == 0) {
} else {
uError("Unsupported url: %s", url);
printf("Unsupported url: %s\n", url);
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
}
@ -1351,7 +1353,7 @@ _exit:
taosMemoryFree(cfgLineBuf);
tjsonDelete(pJson);
if (code != 0) {
uError("failed to load from apollo url:%s at line %d since %s", url, lino, tstrerror(code));
printf("failed to load from apollo url:%s at line %d since %s\n", url, lino, tstrerror(code));
}
TAOS_RETURN(code);
}