Skip to content

Commit

Permalink
Use merr to handle segcore errors (milvus-io#27137)
Browse files Browse the repository at this point in the history
Signed-off-by: Enwei Jiao <[email protected]>
  • Loading branch information
jiaoew1991 authored Sep 18, 2023
1 parent a6b9874 commit 8e17bc3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
15 changes: 4 additions & 11 deletions internal/util/indexcgowrapper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/merr/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/merr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8e17bc3

Please sign in to comment.