Skip to content

Commit c2fcb55

Browse files
optimize error log message for list policy
Signed-off-by: shaoting-huang <[email protected]>
1 parent 9ce3e3c commit c2fcb55

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

internal/rootcoord/root_coord.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,30 +2924,27 @@ func (c *Core) ListPolicy(ctx context.Context, in *internalpb.ListPolicyRequest)
29242924

29252925
policies, err := c.meta.ListPolicy(ctx, util.DefaultTenant)
29262926
if err != nil {
2927-
errMsg := "fail to list policy"
2928-
ctxLog.Warn(errMsg, zap.Error(err))
2927+
ctxLog.Error("fail to list policy", zap.Error(err))
29292928
return &internalpb.ListPolicyResponse{
2930-
Status: merr.StatusWithErrorCode(errors.New(errMsg), commonpb.ErrorCode_ListPolicyFailure),
2929+
Status: merr.StatusWithErrorCode(fmt.Errorf("fail to list policy: %s", err.Error()), commonpb.ErrorCode_ListPolicyFailure),
29312930
}, nil
29322931
}
29332932
// expand privilege groups and turn to policies
29342933
allGroups, err := c.getDefaultAndCustomPrivilegeGroups(ctx)
29352934
if err != nil {
2936-
errMsg := "fail to get privilege groups"
2937-
ctxLog.Warn(errMsg, zap.Error(err))
2935+
ctxLog.Error("fail to get privilege groups", zap.Error(err))
29382936
return &internalpb.ListPolicyResponse{
2939-
Status: merr.StatusWithErrorCode(errors.New(errMsg), commonpb.ErrorCode_ListPolicyFailure),
2937+
Status: merr.StatusWithErrorCode(fmt.Errorf("fail to get privilege groups: %s", err.Error()), commonpb.ErrorCode_ListPolicyFailure),
29402938
}, nil
29412939
}
29422940
groups := lo.SliceToMap(allGroups, func(group *milvuspb.PrivilegeGroupInfo) (string, []*milvuspb.PrivilegeEntity) {
29432941
return group.GroupName, group.Privileges
29442942
})
29452943
expandGrants, err := c.expandPrivilegeGroups(ctx, policies, groups)
29462944
if err != nil {
2947-
errMsg := "fail to expand privilege groups"
2948-
ctxLog.Warn(errMsg, zap.Error(err))
2945+
ctxLog.Error("fail to expand privilege groups", zap.Error(err))
29492946
return &internalpb.ListPolicyResponse{
2950-
Status: merr.StatusWithErrorCode(errors.New(errMsg), commonpb.ErrorCode_ListPolicyFailure),
2947+
Status: merr.StatusWithErrorCode(fmt.Errorf("fail to expand privilege groups: %s", err.Error()), commonpb.ErrorCode_ListPolicyFailure),
29512948
}, nil
29522949
}
29532950
expandPolicies := lo.Map(expandGrants, func(r *milvuspb.GrantEntity, _ int) string {
@@ -2956,10 +2953,9 @@ func (c *Core) ListPolicy(ctx context.Context, in *internalpb.ListPolicyRequest)
29562953

29572954
userRoles, err := c.meta.ListUserRole(ctx, util.DefaultTenant)
29582955
if err != nil {
2959-
errMsg := "fail to list user-role"
2960-
ctxLog.Warn(errMsg, zap.Any("in", in), zap.Error(err))
2956+
ctxLog.Error("fail to list user-role", zap.Any("in", in), zap.Error(err))
29612957
return &internalpb.ListPolicyResponse{
2962-
Status: merr.StatusWithErrorCode(errors.New(errMsg), commonpb.ErrorCode_ListPolicyFailure),
2958+
Status: merr.StatusWithErrorCode(fmt.Errorf("fail to list user-role: %s", err.Error()), commonpb.ErrorCode_ListPolicyFailure),
29632959
}, nil
29642960
}
29652961

0 commit comments

Comments
 (0)