enhance: enable converting segcore error to merr (#29914) (#30178)

this converts the segcore error to merr if possible
pr: #29914

Signed-off-by: yah01 <yang.cen@zilliz.com>
pull/30184/head
yah01 2024-01-22 16:56:55 +08:00 committed by GitHub
parent 1cc5a613d5
commit 0e71923408
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

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

View File

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