diff --git a/internal/querynodev2/segments/cgo_util.go b/internal/querynodev2/segments/cgo_util.go index 7bcb7be055..f56c3fb2cf 100644 --- a/internal/querynodev2/segments/cgo_util.go +++ b/internal/querynodev2/segments/cgo_util.go @@ -33,7 +33,6 @@ import ( "github.com/golang/protobuf/proto" "go.uber.org/zap" - "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/pkg/util/cgoconverter" "github.com/milvus-io/milvus/pkg/util/merr" @@ -45,18 +44,15 @@ func HandleCStatus(ctx context.Context, status *C.CStatus, extraInfo string, fie return nil } errorCode := status.error_code - errorName, ok := commonpb.ErrorCode_name[int32(errorCode)] - if !ok { - errorName = "UnknownError" - } errorMsg := C.GoString(status.error_msg) defer C.free(unsafe.Pointer(status.error_msg)) log.Ctx(ctx).With(fields...). WithOptions(zap.AddCallerSkip(1)) // Add caller stack to show HandleCStatus caller - log.Warn("CStatus returns err", zap.String("errorName", errorName), zap.String("errorMsg", errorMsg)) - return merr.WrapErrServiceInternal(errorName, errorMsg) + err := merr.SegcoreError(int32(errorCode), errorMsg) + log.Warn("CStatus returns err", zap.Error(err)) + return err } // HandleCProto deal with the result proto returned from CGO diff --git a/pkg/util/merr/utils.go b/pkg/util/merr/utils.go index d74cc16ebe..f673577b2b 100644 --- a/pkg/util/merr/utils.go +++ b/pkg/util/merr/utils.go @@ -241,6 +241,11 @@ func Error(status *commonpb.Status) error { return newMilvusErrorWithDetail(status.GetReason(), status.GetDetail(), code, status.GetRetriable()) } +// SegcoreError returns a merr according to the given segcore error code and message +func SegcoreError(code int32, msg string) error { + return newMilvusError(msg, code, false) +} + // CheckHealthy checks whether the state is healthy, // returns nil if healthy, // otherwise returns ErrServiceNotReady wrapped with current state