Skip to content

Commit

Permalink
Add serviceerror.NewerBuildExists (#110) (#111)
Browse files Browse the repository at this point in the history
Co-authored-by: David Reiss <david@temporal.io>
  • Loading branch information
bergundy and dnr authored May 25, 2023
1 parent 7bc2ea3 commit 9405e60
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 51 deletions.
1 change: 1 addition & 0 deletions command/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion common/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion enums/v1/workflow.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions failure/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions history/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions namespace/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions operatorservice/v1/request_response.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion protocol/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions schedule/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions sdk/v1/task_complete_metadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion serviceerror/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func FromStatus(st *status.Status) error {
return errors.New(st.Message())

// Unsupported codes.
case codes.OutOfRange,
case codes.Aborted,
codes.Unauthenticated:
// Use standard gRPC error representation for unsupported codes ("rpc error: code = %s desc = %s").
return st.Err()
Expand Down Expand Up @@ -156,6 +156,13 @@ func FromStatus(st *status.Status) error {
default:
return newPermissionDenied(st, nil)
}
case codes.OutOfRange:
switch errDetails := errDetails.(type) {
case *errordetails.NewerBuildExistsFailure:
return newNewerBuildExists(st, errDetails)
default:
// fall through to st.Err()
}
}

// `st.Code()` has unknown value (should never happen).
Expand Down
77 changes: 77 additions & 0 deletions serviceerror/newer_build_exists.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package serviceerror

import (
"fmt"

"github.com/gogo/status"
"google.golang.org/grpc/codes"

"go.temporal.io/api/errordetails/v1"
)

type (
// NewerBuildExists is returned to a poll request from a build that has been superceded by
// a newer build in versioning metadata.
NewerBuildExists struct {
Message string
DefaultBuildID string
st *status.Status
}
)

// NewNewerBuildExists returns new NewerBuildExists error.
func NewNewerBuildExists(defaultBuildID string) error {
return &NewerBuildExists{
Message: fmt.Sprintf("Task queue has a newer compatible build: %q", defaultBuildID),
DefaultBuildID: defaultBuildID,
}
}

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

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

st := status.New(codes.OutOfRange, e.Message)
st, _ = st.WithDetails(
&errordetails.NewerBuildExistsFailure{
DefaultBuildId: e.DefaultBuildID,
},
)
return st
}

func newNewerBuildExists(st *status.Status, errDetails *errordetails.NewerBuildExistsFailure) error {
return &NewerBuildExists{
Message: st.Message(),
DefaultBuildID: errDetails.GetDefaultBuildId(),
st: st,
}
}
3 changes: 2 additions & 1 deletion taskqueue/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion workflow/v1/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9405e60

Please sign in to comment.