-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NamespaceUnavailable serviceerror
- Loading branch information
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// 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. | ||
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(), | ||
} | ||
} |