Skip to content

Commit

Permalink
Change client/server version support (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin authored Sep 25, 2020
1 parent c2d9c85 commit 222d8b5
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 1,305 deletions.
262 changes: 103 additions & 159 deletions errordetails/v1/message.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 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-20200904194848-62affa334b73 // indirect
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 // indirect
golang.org/x/net v0.0.0-20200923182212-328152dc79b1 // indirect
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20200921165018-b9da36f5f452 // indirect
google.golang.org/genproto v0.0.0-20200925023002-c2d885f95484 // indirect
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0 // indirect
)
12 changes: 6 additions & 6 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-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200923182212-328152dc79b1 h1:Iu68XRPd67wN4aRGGWwwq6bZo/25jR6uu52l/j2KkUE=
golang.org/x/net v0.0.0-20200923182212-328152dc79b1/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-20200922070232-aee5d888a860 h1:YEu4SMq7D0cmT7CBbXfcH0NZeuChAXwsHe/9XueUO6o=
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/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,8 +81,8 @@ 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-20200921165018-b9da36f5f452 h1:2S8dcPkOK9QyAAKa46Cgl//VOCS6ZOsY+iwD3bb9Phg=
google.golang.org/genproto v0.0.0-20200921165018-b9da36f5f452/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200925023002-c2d885f95484 h1:Rr9EZdYRq2WLckzJQVtN3ISKoP7dvgwi7jbglILNZ34=
google.golang.org/genproto v0.0.0-20200925023002-c2d885f95484/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=
Expand Down
12 changes: 6 additions & 6 deletions serviceerror/clientVersionNotSupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ type (
ClientVersionNotSupported struct {
Message string
ClientVersion string
ClientImpl string
ClientName string
SupportedVersions string
st *status.Status
}
)

// NewClientVersionNotSupported returns new ClientVersionNotSupported error.
func NewClientVersionNotSupported(clientVersion, clientImpl, supportedVersions string) *ClientVersionNotSupported {
func NewClientVersionNotSupported(clientVersion, clientName, supportedVersions string) *ClientVersionNotSupported {
return &ClientVersionNotSupported{
Message: fmt.Sprintf("Client version %s is not supported. Supported versions for %s are %s", clientVersion, clientImpl, supportedVersions),
Message: fmt.Sprintf("Client version %s is not supported. Server supports %s versions: %s", clientVersion, clientName, supportedVersions),
ClientVersion: clientVersion,
ClientImpl: clientImpl,
ClientName: clientName,
SupportedVersions: supportedVersions,
}
}
Expand All @@ -66,7 +66,7 @@ func (e *ClientVersionNotSupported) Status() *status.Status {
st, _ = st.WithDetails(
&errordetails.ClientVersionNotSupportedFailure{
ClientVersion: e.ClientVersion,
ClientImpl: e.ClientImpl,
ClientName: e.ClientName,
SupportedVersions: e.SupportedVersions,
},
)
Expand All @@ -77,7 +77,7 @@ func newClientVersionNotSupported(st *status.Status, errDetails *errordetails.Cl
return &ClientVersionNotSupported{
Message: st.Message(),
ClientVersion: errDetails.GetClientVersion(),
ClientImpl: errDetails.GetClientImpl(),
ClientName: errDetails.GetClientName(),
SupportedVersions: errDetails.GetSupportedVersions(),
st: st,
}
Expand Down
4 changes: 2 additions & 2 deletions serviceerror/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func FromStatus(st *status.Status) error {
return newNamespaceNotActive(st, errDetails)
case *errordetails.ClientVersionNotSupportedFailure:
return newClientVersionNotSupported(st, errDetails)
case *errordetails.FeatureVersionNotSupportedFailure:
return newFeatureVersionNotSupported(st, errDetails)
case *errordetails.ServerVersionNotSupportedFailure:
return newServerVersionNotSupported(st, errDetails)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,49 @@ import (
)

type (
// FeatureVersionNotSupported represents client version is not supported error.
FeatureVersionNotSupported struct {
Message string
FeatureVersion string
Feature string
SupportedVersions string
st *status.Status
// ServerVersionNotSupported represents client version is not supported error.
ServerVersionNotSupported struct {
Message string
ServerVersion string
ClientSupportedServerVersions string
st *status.Status
}
)

// NewFeatureVersionNotSupported returns new FeatureVersionNotSupported error.
func NewFeatureVersionNotSupported(feature, featureVersion, supportedVersions string) *FeatureVersionNotSupported {
return &FeatureVersionNotSupported{
Message: fmt.Sprintf("Feature %s is not supported in feature set version %s. At least %s feature set version is required", feature, featureVersion, supportedVersions),
FeatureVersion: featureVersion,
Feature: feature,
SupportedVersions: supportedVersions,
// NewServerVersionNotSupported returns new ServerVersionNotSupported error.
func NewServerVersionNotSupported(serverVersion, supportedVersions string) *ServerVersionNotSupported {
return &ServerVersionNotSupported{
Message: fmt.Sprintf("Server version %s is not supported. Client supports server versions: %s", serverVersion, supportedVersions),
ServerVersion: serverVersion,
ClientSupportedServerVersions: supportedVersions,
}
}

// Error returns string message.
func (e *FeatureVersionNotSupported) Error() string {
func (e *ServerVersionNotSupported) Error() string {
return e.Message
}

func (e *FeatureVersionNotSupported) Status() *status.Status {
func (e *ServerVersionNotSupported) Status() *status.Status {
if e.st != nil {
return e.st
}

st := status.New(codes.FailedPrecondition, e.Message)
st, _ = st.WithDetails(
&errordetails.FeatureVersionNotSupportedFailure{
FeatureVersion: e.FeatureVersion,
Feature: e.Feature,
SupportedVersions: e.SupportedVersions,
&errordetails.ServerVersionNotSupportedFailure{
ServerVersion: e.ServerVersion,
ClientSupportedServerVersions: e.ClientSupportedServerVersions,
},
)
return st
}

func newFeatureVersionNotSupported(st *status.Status, errDetails *errordetails.FeatureVersionNotSupportedFailure) *FeatureVersionNotSupported {
return &FeatureVersionNotSupported{
Message: st.Message(),
FeatureVersion: errDetails.GetFeatureVersion(),
Feature: errDetails.GetFeature(),
SupportedVersions: errDetails.GetSupportedVersions(),
st: st,
func newServerVersionNotSupported(st *status.Status, errDetails *errordetails.ServerVersionNotSupportedFailure) *ServerVersionNotSupported {
return &ServerVersionNotSupported{
Message: st.Message(),
ServerVersion: errDetails.GetServerVersion(),
ClientSupportedServerVersions: errDetails.GetClientSupportedServerVersions(),
st: st,
}
}
Loading

0 comments on commit 222d8b5

Please sign in to comment.