Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion serviceerror/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ func FromStatus(st *status.Status) error {
case codes.Canceled:
return newCanceled(st)
case codes.Unavailable:
return newUnavailable(st)
switch errDetails := errDetails.(type) {
case *errordetails.NamespaceUnavailableFailure:
return newNamespaceUnavailable(st, errDetails)
default:
return newUnavailable(st)
}
case codes.Unimplemented:
return newUnimplemented(st)
case codes.Unknown:
Expand Down
80 changes: 80 additions & 0 deletions serviceerror/namespace_unavailable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// The MIT License
//
// Copyright (c) 2024 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"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

type (
// NamespaceUnavailable is returned by the service when a request addresses a namespace that is unavailable. For
// example, when a namespace is in the process of failing over between clusters. This is a transient error that
// should be automatically retried by clients.
NamespaceUnavailable struct {
Namespace string
// Note that other service errors have a private status.Status field, there's no compelling reason to do
// copy that pattern here. The status can and should be computed on the fly in case the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a compelling reason to not copy the pattern? Technically one reason that copying the pattern is that the status object could contain additional details. But that's not likely to happen. Still, I see no good reason not to keep the status object as we always have.

Copy link
Member Author

@bergundy bergundy Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually thinking of taking it to the other direction and not even keeping the message from the wire. That way if the error is mutated (e.g. a different Namespace string is set, it is serialized correctly).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't put too much thought into it, just keep the status you're given like other similar errors

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, I'll just do that to move things along. I wanted to improve what we had, but I can see arguments in both directions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// We'll just store the message from the wire here in case the code that generates it changes.
messageFromWire string
}
)

// NewNamespaceUnavailable returns new NamespaceInvalidState error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NamespaceInvalidState error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I should have replaced with /g.

func NewNamespaceUnavailable(namespace string) error {
return &NamespaceUnavailable{
Namespace: namespace,
}
}

// Error returns string message.
func (e *NamespaceUnavailable) Error() string {
if e.messageFromWire != "" {
return e.messageFromWire
}
// Continuing the practice of starting errors with upper case and ending with periods even if it's not
// idiomatic.
return fmt.Sprintf("Namespace unavailable: %q.", e.Namespace)
}

func (e *NamespaceUnavailable) Status() *status.Status {
st := status.New(codes.Unavailable, e.Error())
// We seem to be okay ignoring these errors everywhere else, doing this here too.
st, _ = st.WithDetails(
&errordetails.NamespaceUnavailableFailure{
Namespace: e.Namespace,
},
)
return st
}

func newNamespaceUnavailable(st *status.Status, errDetails *errordetails.NamespaceUnavailableFailure) error {
return &NamespaceUnavailable{
messageFromWire: st.Message(),
Namespace: errDetails.GetNamespace(),
}
}