From caf3a2405dbe77f4a7d834e6897c174af840ba54 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Mon, 8 Nov 2021 22:05:05 +0800 Subject: [PATCH] Update KnowhereException (#11425) Signed-off-by: yudong.cai --- .../knowhere/knowhere/common/Exception.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/core/src/index/knowhere/knowhere/common/Exception.cpp b/internal/core/src/index/knowhere/knowhere/common/Exception.cpp index 557b9cd50c..7c379ab790 100644 --- a/internal/core/src/index/knowhere/knowhere/common/Exception.cpp +++ b/internal/core/src/index/knowhere/knowhere/common/Exception.cpp @@ -10,7 +10,6 @@ // or implied. See the License for the specific language governing permissions and limitations under the License #include -#include #include #include "Log.h" @@ -23,13 +22,19 @@ KnowhereException::KnowhereException(std::string msg) : msg_(std::move(msg)) { } KnowhereException::KnowhereException(const std::string& m, const char* funcName, const char* file, int line) { - const char* filename = funcName; - while (auto tmp = strchr(filename, '/')) { - filename = tmp + 1; + std::string filename; + try { + size_t pos; + std::string file_path(file); + pos = file_path.find_last_of('/'); + filename = file_path.substr(pos + 1); + } catch (std::exception& e) { + LOG_KNOWHERE_ERROR_ << e.what(); } - int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, filename, line, m.c_str()); + + int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str()); msg_.resize(size + 1); - snprintf(msg_.data(), m.size(), "Error in %s at %s:%d: %s", funcName, filename, line, m.c_str()); + snprintf(&msg_[0], msg_.size(), "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str()); } const char*