mirror of https://github.com/milvus-io/milvus.git
enhance: catch std::stoi exception and improve error msg (#36267)
issue: #36255 Signed-off-by: jaime <yun.zhang@zilliz.com>pull/36291/head
parent
3352030a84
commit
2ff3765058
|
@ -128,7 +128,14 @@ int64_t
|
|||
GetDimFromConfig(const Config& config) {
|
||||
auto dimension = GetValueFromConfig<std::string>(config, "dim");
|
||||
AssertInfo(dimension.has_value(), "dimension not exist in config");
|
||||
return (std::stoi(dimension.value()));
|
||||
try {
|
||||
return (std::stoi(dimension.value()));
|
||||
} catch (const std::logic_error& e) {
|
||||
auto err_message = fmt::format(
|
||||
"invalided dimension:{}, error:{}", dimension.value(), e.what());
|
||||
LOG_ERROR(err_message);
|
||||
throw std::logic_error(err_message);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
|
@ -151,7 +158,16 @@ GetIndexEngineVersionFromConfig(const Config& config) {
|
|||
GetValueFromConfig<std::string>(config, INDEX_ENGINE_VERSION);
|
||||
AssertInfo(index_engine_version.has_value(),
|
||||
"index_engine not exist in config");
|
||||
return (std::stoi(index_engine_version.value()));
|
||||
try {
|
||||
return (std::stoi(index_engine_version.value()));
|
||||
} catch (const std::logic_error& e) {
|
||||
auto err_message =
|
||||
fmt::format("invalided index engine version:{}, error:{}",
|
||||
index_engine_version.value(),
|
||||
e.what());
|
||||
LOG_ERROR(err_message);
|
||||
throw std::logic_error(err_message);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t
|
||||
|
@ -160,7 +176,15 @@ GetBitmapCardinalityLimitFromConfig(const Config& config) {
|
|||
config, index::BITMAP_INDEX_CARDINALITY_LIMIT);
|
||||
AssertInfo(bitmap_limit.has_value(),
|
||||
"bitmap cardinality limit not exist in config");
|
||||
return (std::stoi(bitmap_limit.value()));
|
||||
try {
|
||||
return (std::stoi(bitmap_limit.value()));
|
||||
} catch (const std::logic_error& e) {
|
||||
auto err_message = fmt::format("invalided bitmap limit:{}, error:{}",
|
||||
bitmap_limit.value(),
|
||||
e.what());
|
||||
LOG_ERROR(err_message);
|
||||
throw std::logic_error(err_message);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO :: too ugly
|
||||
|
|
|
@ -244,8 +244,16 @@ DiskFileManagerImpl::CacheIndexToDisk(
|
|||
std::map<std::string, std::vector<int>> index_slices;
|
||||
for (auto& file_path : remote_files) {
|
||||
auto pos = file_path.find_last_of('_');
|
||||
index_slices[file_path.substr(0, pos)].emplace_back(
|
||||
std::stoi(file_path.substr(pos + 1)));
|
||||
AssertInfo(pos > 0, "invalided index file path:{}", file_path);
|
||||
try {
|
||||
auto idx = std::stoi(file_path.substr(pos + 1));
|
||||
index_slices[file_path.substr(0, pos)].emplace_back(idx);
|
||||
} catch (const std::logic_error& e) {
|
||||
auto err_message = fmt::format(
|
||||
"invalided index file path:{}, error:{}", file_path, e.what());
|
||||
LOG_ERROR(err_message);
|
||||
throw std::logic_error(err_message);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& slices : index_slices) {
|
||||
|
@ -303,9 +311,17 @@ DiskFileManagerImpl::CacheTextLogToDisk(
|
|||
|
||||
std::map<std::string, std::vector<int>> index_slices;
|
||||
for (auto& file_path : remote_files) {
|
||||
auto pos = file_path.find_last_of('_');
|
||||
index_slices[file_path.substr(0, pos)].emplace_back(
|
||||
std::stoi(file_path.substr(pos + 1)));
|
||||
auto pos = file_path.find_last_of("_");
|
||||
AssertInfo(pos > 0, "invalided index file path:{}", file_path);
|
||||
try {
|
||||
auto idx = std::stoi(file_path.substr(pos + 1));
|
||||
index_slices[file_path.substr(0, pos)].emplace_back(idx);
|
||||
} catch (const std::logic_error& e) {
|
||||
auto err_message = fmt::format(
|
||||
"invalided text log path:{}, error:{}", file_path, e.what());
|
||||
LOG_ERROR(err_message);
|
||||
throw std::logic_error(err_message);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& slices : index_slices) {
|
||||
|
|
Loading…
Reference in New Issue