catch-load-config-exception (#3857)

Signed-off-by: Wang Xiangyu <xy.wang@zilliz.com>

remove unused code

Signed-off-by: Wang Xiangyu <xy.wang@zilliz.com>
This commit is contained in:
Wang Xiangyu 2020-09-24 18:01:32 +08:00 committed by GitHub
parent a04a8ad1ff
commit 367c996b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 17 deletions

View File

@ -43,7 +43,7 @@ Flatten(const YAML::Node& node, std::unordered_map<std::string, std::string>& ta
break;
}
case YAML::NodeType::Undefined: {
throw "Unexpected";
std::runtime_error("Undefined YAML Node is not supported in Flatten.");
}
default:
break;
@ -123,27 +123,39 @@ ConfigMgr::Init() {
void
ConfigMgr::LoadFile(const std::string& path) {
/* load from milvus.yaml */
auto yaml = YAML::LoadFile(path);
try {
/* load from milvus.yaml */
auto yaml = YAML::LoadFile(path);
/* make it flattened */
std::unordered_map<std::string, std::string> flattened;
Flatten(yaml, flattened, "");
/* make it flattened */
std::unordered_map<std::string, std::string> flattened;
Flatten(yaml, flattened, "");
/* update config */
for (auto& it : flattened) Set(it.first, it.second, false);
/* update config */
for (auto& it : flattened) Set(it.first, it.second, false);
} catch (std::exception& ex) {
throw;
} catch (...) {
throw std::runtime_error("Unknown error occurred.");
}
}
void
ConfigMgr::LoadMemory(const std::string& yaml_string) {
auto yaml = YAML::Load(yaml_string);
try {
auto yaml = YAML::Load(yaml_string);
/* make it flattened */
std::unordered_map<std::string, std::string> flattened;
Flatten(yaml, flattened, "");
/* make it flattened */
std::unordered_map<std::string, std::string> flattened;
Flatten(yaml, flattened, "");
/* update config */
for (auto& it : flattened) Set(it.first, it.second, false);
/* update config */
for (auto& it : flattened) Set(it.first, it.second, false);
} catch (std::exception& ex) {
throw;
} catch (...) {
throw std::runtime_error("Unknown error occurred.");
}
}
void

View File

@ -90,10 +90,12 @@ class ConfigMgr : public BaseConfigMgr {
void
Init();
/* throws std::exception only */
void
LoadFile(const std::string& path);
/* for testing */
/* throws std::exception only */
void
LoadMemory(const std::string& yaml_string);

View File

@ -93,7 +93,6 @@ main(int argc, char* argv[]) {
char* config_filename_ptr = strdup(optarg);
config_filename = config_filename_ptr;
free(config_filename_ptr);
std::cout << "Loading configuration from: " << config_filename << std::endl;
break;
}
case 'p': {
@ -134,8 +133,12 @@ main(int argc, char* argv[]) {
milvus::ConfigMgr::GetInstance().Init();
milvus::ConfigMgr::GetInstance().LoadFile(config_filename);
milvus::ConfigMgr::GetInstance().FilePath() = config_filename;
} catch (milvus::ConfigStatus& cs) {
std::cerr << "Load config(" << config_filename << ") failed: " << cs.message << std::endl;
std::cout << "Successfully load configuration from " << config_filename << "." << std::endl;
} catch (std::exception& ex) {
std::cerr << "Load configuration file " << config_filename << " failed: " << ex.what() << std::endl;
goto FAIL;
} catch (...) {
std::cerr << "Load configuration file " << config_filename << " failed: Unknown error." << std::endl;
goto FAIL;
}