From c196c55381efea0acb72d9ecc83853ffce7d1889 Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:25:50 +0800 Subject: [PATCH] Improve the assert information (#22578) Signed-off-by: lixinguo Co-authored-by: lixinguo --- internal/core/src/segcore/ConcurrentVector.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/core/src/segcore/ConcurrentVector.h b/internal/core/src/segcore/ConcurrentVector.h index 7acefb2e2e..f5b5bb2dcb 100644 --- a/internal/core/src/segcore/ConcurrentVector.h +++ b/internal/core/src/segcore/ConcurrentVector.h @@ -49,14 +49,18 @@ class ThreadSafeVector { } const Type& operator[](int64_t index) const { - Assert(index < size_); + AssertInfo(index < size_, + fmt::format( + "index out of range, index={}, size_={}", index, size_)); std::shared_lock lck(mutex_); return vec_[index]; } Type& operator[](int64_t index) { - Assert(index < size_); + AssertInfo(index < size_, + fmt::format( + "index out of range, index={}, size_={}", index, size_)); std::shared_lock lck(mutex_); return vec_[index]; } @@ -271,7 +275,8 @@ class ConcurrentVectorImpl : public VectorBase { const Type& operator[](ssize_t element_index) const { - Assert(Dim == 1); + AssertInfo(Dim == 1, + fmt::format("The value of Dim is not 1, Dim={}", Dim)); auto chunk_id = element_index / size_per_chunk_; auto chunk_offset = element_index % size_per_chunk_; return get_chunk(chunk_id)[chunk_offset]; @@ -353,7 +358,8 @@ class ConcurrentVector public: explicit ConcurrentVector(int64_t dim, int64_t size_per_chunk) : binary_dim_(dim), ConcurrentVectorImpl(dim / 8, size_per_chunk) { - Assert(dim % 8 == 0); + AssertInfo(dim % 8 == 0, + fmt::format("dim is not a multiple of 8, dim={}", dim)); } private: