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 <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2024-05-27 14:33:41 +08:00 committed by GitHub
parent af71116499
commit 5cf4161394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View File

@ -14,6 +14,7 @@
#include <atomic>
#include <exception>
#include <optional>
#include "Exception.h"
namespace milvus {
template <typename T>
@ -55,7 +56,7 @@ class Channel {
}
void
close(std::optional<std::exception> ex = std::nullopt) {
close(std::optional<MilvusException> ex = std::nullopt) {
if (ex.has_value()) {
ex_ = std::move(ex);
}
@ -64,6 +65,6 @@ class Channel {
private:
oneapi::tbb::concurrent_bounded_queue<std::optional<T>> inner_{};
std::optional<std::exception> ex_{};
std::optional<MilvusException> ex_{};
};
} // namespace milvus

View File

@ -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)

View File

@ -820,7 +820,7 @@ LoadFieldDatasFromRemote(const std::vector<std::string>& 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()));
}
}