From 5cf41613943f90cdad5eaffc99de63ca29c2fa86 Mon Sep 17 00:00:00 2001 From: "yihao.dai" Date: Mon, 27 May 2024 14:33:41 +0800 Subject: [PATCH] fix: Fix exception info is missing (#33393) Replace based std::exception to prevent "object slicing" issue: https://github.com/milvus-io/milvus/issues/33392 Signed-off-by: bigsheeper --- internal/core/src/common/Channel.h | 5 +++-- internal/core/src/common/Exception.h | 16 ++++++++++++++++ internal/core/src/segcore/Utils.cpp | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/core/src/common/Channel.h b/internal/core/src/common/Channel.h index f042945432..1dead83247 100644 --- a/internal/core/src/common/Channel.h +++ b/internal/core/src/common/Channel.h @@ -14,6 +14,7 @@ #include #include #include +#include "Exception.h" namespace milvus { template @@ -55,7 +56,7 @@ class Channel { } void - close(std::optional ex = std::nullopt) { + close(std::optional ex = std::nullopt) { if (ex.has_value()) { ex_ = std::move(ex); } @@ -64,6 +65,6 @@ class Channel { private: oneapi::tbb::concurrent_bounded_queue> inner_{}; - std::optional ex_{}; + std::optional ex_{}; }; } // namespace milvus diff --git a/internal/core/src/common/Exception.h b/internal/core/src/common/Exception.h index 68941ba567..d4f3863b9d 100644 --- a/internal/core/src/common/Exception.h +++ b/internal/core/src/common/Exception.h @@ -20,6 +20,22 @@ namespace milvus { +class MilvusException : public std::exception { + public: + explicit MilvusException(const std::string& msg) + : std::exception(), exception_message_(msg) { + } + const char* + what() const noexcept { + return exception_message_.c_str(); + } + virtual ~MilvusException() { + } + + private: + std::string exception_message_; +}; + class NotImplementedException : public std::exception { public: explicit NotImplementedException(const std::string& msg) diff --git a/internal/core/src/segcore/Utils.cpp b/internal/core/src/segcore/Utils.cpp index cee4a04c92..6349ad847a 100644 --- a/internal/core/src/segcore/Utils.cpp +++ b/internal/core/src/segcore/Utils.cpp @@ -820,7 +820,7 @@ LoadFieldDatasFromRemote(const std::vector& remote_files, channel->close(); } catch (std::exception& e) { LOG_INFO("failed to load data from remote: {}", e.what()); - channel->close(std::move(e)); + channel->close(MilvusException(e.what())); } }