From af6f0d5aa5d50abd44ec09003c58fc057bb9d083 Mon Sep 17 00:00:00 2001 From: congqixia Date: Fri, 10 Mar 2023 22:37:53 +0800 Subject: [PATCH] Make merr.Error(status) read old error code (#22698) Signed-off-by: Congqi Xia --- internal/util/merr/utils.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/util/merr/utils.go b/internal/util/merr/utils.go index c74d7da52b..56b7bf2ecd 100644 --- a/internal/util/merr/utils.go +++ b/internal/util/merr/utils.go @@ -19,6 +19,7 @@ package merr import ( "context" + "fmt" "strings" "github.com/cockroachdb/errors" @@ -73,11 +74,17 @@ func Status(err error) *commonpb.Status { // Error returns a error according to the given status, // returns nil if the status is a success status func Error(status *commonpb.Status) error { - if status.Code == 0 { + if status.GetCode() == 0 && status.GetErrorCode() == commonpb.ErrorCode_Success { return nil } - return newMilvusError(status.GetReason(), status.Code, status.Code&retriableFlag != 0) + // use code first + code := status.GetCode() + if code == 0 { + return newMilvusError(fmt.Sprintf("legacy error code:%d, reason: %s", status.GetErrorCode(), status.GetReason()), errUnexpected.errCode, false) + } + + return newMilvusError(status.GetReason(), code, code&retriableFlag != 0) } // Service related