Make merr.Error(status) read old error code (#22698)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/22701/head
congqixia 2023-03-10 22:37:53 +08:00 committed by GitHub
parent 1a4732bb19
commit af6f0d5aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

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