diff --git a/internal/errorcodes/errorcodes.go b/internal/errorcodes/errorcodes.go index de9f75f867..2d392c3469 100644 --- a/internal/errorcodes/errorcodes.go +++ b/internal/errorcodes/errorcodes.go @@ -45,21 +45,16 @@ func FeatureEnabled(md map[string]string) bool { // NewStatusError returns a Status representing Code, error Reason, Message, and optional ResourceInfo and Metadata. // When successful, it returns a StatusError, otherwise returns the original error -func NewStatusError(code codes.Code, err error, errDescription string, reason Reason, rid *ResourceInfoData, metadata map[string]string) error { - md := metadata - if md == nil { - md = map[string]string{} - } - +func NewStatusError(code codes.Code, err error, reason Reason, rid *ResourceInfoData, metadata map[string]string) error { messages := []protoiface.MessageV1{ - NewErrorInfo(reason, md), + NewErrorInfo(reason, metadata), } if rid != nil { - messages = append(messages, NewResourceInfo(rid, errDescription)) + messages = append(messages, NewResourceInfo(rid, err)) } - ste, stErr := status.New(code, errDescription).WithDetails(messages...) + ste, stErr := status.New(code, err.Error()).WithDetails(messages...) if stErr != nil { return err } @@ -77,11 +72,11 @@ func NewErrorInfo(reason Reason, md map[string]string) *errdetails.ErrorInfo { return &ei } -func NewResourceInfo(rid *ResourceInfoData, description string) *errdetails.ResourceInfo { +func NewResourceInfo(rid *ResourceInfoData, err error) *errdetails.ResourceInfo { return &errdetails.ResourceInfo{ ResourceType: rid.ResourceType, ResourceName: rid.ResourceName, Owner: Owner, - Description: description, + Description: err.Error(), } } diff --git a/state/redis/redis.go b/state/redis/redis.go index 90bceb10b1..1e4aa36508 100644 --- a/state/redis/redis.go +++ b/state/redis/redis.go @@ -221,8 +221,8 @@ func (r *StateStore) Delete(ctx context.Context, req *state.DeleteRequest) error } if err != nil { if errorcodes.FeatureEnabled(req.Metadata) { - errMsg := fmt.Sprintf("state store Delete - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err) - return errorcodes.NewStatusError(codes.InvalidArgument, err, errMsg, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil) + ew := fmt.Errorf("state store Delete - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err) + return errorcodes.NewStatusError(codes.InvalidArgument, ew, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil) } return state.NewETagError(state.ETagMismatch, err) @@ -367,8 +367,8 @@ func (r *StateStore) Set(ctx context.Context, req *state.SetRequest) error { if err != nil { if req.HasETag() { if errorcodes.FeatureEnabled(req.Metadata) { - errMsg := fmt.Sprintf("state store Set - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err) - return errorcodes.NewStatusError(codes.InvalidArgument, fmt.Errorf(errMsg), errMsg, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil) + ew := fmt.Errorf("state store Set - possible etag(%s) %s. original error: %v", *req.ETag, string(state.ETagMismatch), err) + return errorcodes.NewStatusError(codes.InvalidArgument, ew, errorcodes.StateETagMismatchReason, &r.resourceInfoData, nil) } return state.NewETagError(state.ETagMismatch, err)