diff --git a/internal/util/indexcgowrapper/helper.go b/internal/util/indexcgowrapper/helper.go index 5de29422f4419..142b9f76a769d 100644 --- a/internal/util/indexcgowrapper/helper.go +++ b/internal/util/indexcgowrapper/helper.go @@ -13,10 +13,8 @@ import ( "fmt" "unsafe" - "github.com/cockroachdb/errors" - - "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus/pkg/log" + "github.com/milvus-io/milvus/pkg/util/merr" ) func GetBinarySetKeys(cBinarySet C.CBinarySet) ([]string, error) { @@ -65,18 +63,13 @@ func HandleCStatus(status *C.CStatus, extraInfo string) error { if status.error_code == 0 { return nil } - errorCode := status.error_code - errorName, ok := commonpb.ErrorCode_name[int32(errorCode)] - if !ok { - errorName = "UnknownError" - } + errorCode := int(status.error_code) errorMsg := C.GoString(status.error_msg) defer C.free(unsafe.Pointer(status.error_msg)) - finalMsg := fmt.Sprintf("[%s] %s", errorName, errorMsg) - logMsg := fmt.Sprintf("%s, C Runtime Exception: %s\n", extraInfo, finalMsg) + logMsg := fmt.Sprintf("%s, C Runtime Exception: %s\n", extraInfo, errorMsg) log.Warn(logMsg) - return errors.New(finalMsg) + return merr.WrapErrSegcore(int32(errorCode), logMsg) } func GetLocalUsedSize(path string) (int64, error) { diff --git a/pkg/util/merr/errors.go b/pkg/util/merr/errors.go index a36a9ef9bad4b..8870260850b5e 100644 --- a/pkg/util/merr/errors.go +++ b/pkg/util/merr/errors.go @@ -113,6 +113,9 @@ var ( ErrInvalidSearchResult = newMilvusError("fail to parse search result", 1805, false) ErrCheckPrimaryKey = newMilvusError("please check the primary key and its' type can only in [int, string]", 1806, false) + // Segcore related + ErrSegcore = newMilvusError("segcore error", 2000, false) + // Do NOT export this, // never allow programmer using this, keep only for converting unknown error to milvusError errUnexpected = newMilvusError("unexpected error", (1<<16)-1, false) diff --git a/pkg/util/merr/utils.go b/pkg/util/merr/utils.go index 5a9dd8c40e689..c556ac9e6e4ac 100644 --- a/pkg/util/merr/utils.go +++ b/pkg/util/merr/utils.go @@ -518,6 +518,15 @@ func WrapErrMqInternal(err error, msg ...string) error { return err } +// Segcore related +func WrapErrSegcore(code int32, msg ...string) error { + err := errors.Wrapf(ErrSegcore, "internal code=%v", code) + if len(msg) > 0 { + err = errors.Wrap(err, strings.Join(msg, "; ")) + } + return err +} + // field related func WrapErrFieldNotFound[T any](field T, msg ...string) error { err := errors.Wrapf(ErrFieldNotFound, "field=%v", field)