Skip to content

Commit

Permalink
Export Status method of ServiceError interface (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin authored Sep 18, 2020
1 parent cfb813c commit 8384052
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
github.com/gogo/status v1.1.0
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.2 // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
golang.org/x/sys v0.0.0-20200917073148-efd3b9a0ff20 // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20200831141814-d751682dd103 // indirect
google.golang.org/grpc v1.31.1
google.golang.org/genproto v0.0.0-20200917134801-bb4cff56e0d0 // indirect
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -61,8 +61,8 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a h1:i47hUS795cOydZI4AwJQCKXOr4BvxzvikwDoDtHhP2Y=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200917073148-efd3b9a0ff20 h1:4X356008q5SA3YXu8PiRap39KFmy4Lf6sGlceJKZQsU=
golang.org/x/sys v0.0.0-20200917073148-efd3b9a0ff20/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -81,15 +81,15 @@ google.golang.org/genproto v0.0.0-20180518175338-11a468237815/go.mod h1:JiN7NxoA
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20200831141814-d751682dd103 h1:z46CEPU+LlO0kGGwrH8h5epkkJhRZbAHYWOWD9JhLPI=
google.golang.org/genproto v0.0.0-20200831141814-d751682dd103/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200917134801-bb4cff56e0d0 h1:uslsjIdqvZYANxSBQjTI47vZfwMaTN3mLELkMnMIY/A=
google.golang.org/genproto v0.0.0-20200917134801-bb4cff56e0d0/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs=
google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/canceled.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *Canceled) Error() string {
return e.Message
}

func (e *Canceled) status() *status.Status {
func (e *Canceled) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/cancellationAlreadyRequested.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (e *CancellationAlreadyRequested) Error() string {
return e.Message
}

func (e *CancellationAlreadyRequested) status() *status.Status {
func (e *CancellationAlreadyRequested) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/clientVersionNotSupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e *ClientVersionNotSupported) Error() string {
return e.Message
}

func (e *ClientVersionNotSupported) status() *status.Status {
func (e *ClientVersionNotSupported) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
8 changes: 4 additions & 4 deletions serviceerror/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ import (
"go.temporal.io/api/errordetails/v1"
)

// ToStatus converts service error to gogo gRPC status.
// ToStatus converts service error to gogo gRPC Status.
// If error is not a service error it returns status with code Unknown.
func ToStatus(err error) *status.Status {
if err == nil {
return status.New(codes.OK, "")
}

if svcerr, ok := err.(ServiceError); ok {
return svcerr.status()
return svcerr.Status()
}

// Special case for context.DeadlineExceeded because it can happened in unpredictable places.
Expand All @@ -49,12 +49,12 @@ func ToStatus(err error) *status.Status {
}

// Internal logic of status.Convert is:
// - if err is already gogo Status or gRPC status, then just return it (this should never happen though).
// - if err is already gogo Status or gRPC Status, then just return it (this should never happen though).
// - otherwise returns codes.Unknown with message from err.Error() (this might happen if some generic go error reach to this point).
return status.Convert(err)
}

// FromStatus converts gogo gRPC status to service error.
// FromStatus converts gogo gRPC Status to service error.
func FromStatus(st *status.Status) error {
if st == nil || st.Code() == codes.OK {
return nil
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/dataLoss.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *DataLoss) Error() string {
return e.Message
}

func (e *DataLoss) status() *status.Status {
func (e *DataLoss) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/deadlineExceeded.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *DeadlineExceeded) Error() string {
return e.Message
}

func (e *DeadlineExceeded) status() *status.Status {
func (e *DeadlineExceeded) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/featureVersionNotSupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e *FeatureVersionNotSupported) Error() string {
return e.Message
}

func (e *FeatureVersionNotSupported) status() *status.Status {
func (e *FeatureVersionNotSupported) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (e *Internal) Error() string {
return e.Message
}

func (e *Internal) status() *status.Status {
func (e *Internal) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/invalidArgument.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (e *InvalidArgument) Error() string {
return e.Message
}

func (e *InvalidArgument) status() *status.Status {
func (e *InvalidArgument) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/namespaceAlreadyExists.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (e *NamespaceAlreadyExists) Error() string {
return e.Message
}

func (e *NamespaceAlreadyExists) status() *status.Status {
func (e *NamespaceAlreadyExists) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/namespaceNotActive.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (e *NamespaceNotActive) Error() string {
return e.Message
}

func (e *NamespaceNotActive) status() *status.Status {
func (e *NamespaceNotActive) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/notFound.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (e *NotFound) Error() string {
return e.Message
}

func (e *NotFound) status() *status.Status {
func (e *NotFound) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/permissionDenied.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *PermissionDenied) Error() string {
return e.Message
}

func (e *PermissionDenied) status() *status.Status {
func (e *PermissionDenied) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/queryFailed.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (e *QueryFailed) Error() string {
return e.Message
}

func (e *QueryFailed) status() *status.Status {
func (e *QueryFailed) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/resourceExhausted.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *ResourceExhausted) Error() string {
return e.Message
}

func (e *ResourceExhausted) status() *status.Status {
func (e *ResourceExhausted) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/serviceerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import "github.com/gogo/status"
type (
ServiceError interface {
error
status() *status.Status
Status() *status.Status
}
)
2 changes: 1 addition & 1 deletion serviceerror/unavailable.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *Unavailable) Error() string {
return e.Message
}

func (e *Unavailable) status() *status.Status {
func (e *Unavailable) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *Unimplemented) Error() string {
return e.Message
}

func (e *Unimplemented) status() *status.Status {
func (e *Unimplemented) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/workflowExecutionAlreadyStarted.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (e *WorkflowExecutionAlreadyStarted) Error() string {
return e.Message
}

func (e *WorkflowExecutionAlreadyStarted) status() *status.Status {
func (e *WorkflowExecutionAlreadyStarted) Status() *status.Status {
if e.st != nil {
return e.st
}
Expand Down

0 comments on commit 8384052

Please sign in to comment.