Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
13 changes: 11 additions & 2 deletions serviceerror/already_exists.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -13,13 +15,20 @@ type (
}
)

// NewAlreadyExist returns new AlreadyExists error.
func NewAlreadyExist(message string) error {
Copy link
Member

Choose a reason for hiding this comment

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

We can't make backwards-incompatible changes to this package IMO (even if users shouldn't really be using it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not used by SDK. Only by server. But I agree... I should leave old constructor as deprecated.

Copy link
Member

@cretz cretz May 14, 2025

Choose a reason for hiding this comment

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

We do not know everyone that uses this. The go.temporal.io/api library is one of the most included depended-upon libraries by Temporal users (granted usually transitively). Many users have proxies, client mocks, etc that may take advantage of these things. We should not adjust this library as if it's only used by server, https://github.com/temporalio/temporal is a better place for code that is only used by server.

// NewAlreadyExists returns new AlreadyExists error.
func NewAlreadyExists(message string) error {
return &AlreadyExists{
Message: message,
}
}

// NewAlreadyExistsf returns new AlreadyExists error with formatted message.
func NewAlreadyExistsf(format string, args ...any) error {
Copy link
Member

Choose a reason for hiding this comment

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

Users are not really expected to create these errors, do we really need new user-facing helpers? What is the use case driving this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These errors are constructed mostly on server. User is a server dev. We have hundreds of usages with fmt.Sprintf and even small helpers like this. I want to get rid of all these helpers.

Copy link
Member

@cretz cretz May 14, 2025

Choose a reason for hiding this comment

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

User of this library is more than server dev. I don't think we need to update this user-facing package with server-dev-only utilities. You aren't getting rid of the helpers, you're moving them to the this public, user-facing library for everyone. If the user is server dev, can it be put somewhere only for server dev?

Copy link
Contributor

Choose a reason for hiding this comment

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

Go SDK has several instances of serviceerror.New<Something>(fmt.Sprintf(...)), it can and should also use these new constructors.

Also, it would be pretty weird to have the NewSomething constructor be in this package but the NewSomethingf constructor be in a whole other package.

Copy link
Contributor Author

@alexshtin alexshtin May 14, 2025

Choose a reason for hiding this comment

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

serviceerror package should NOT be in this repo at all. This is a mistake I made long time ago. Having constructor separate from struct definition doesn't look good to me. And yes, if other users use New<Something> they will definitely benefit from these new constructors too.

Copy link
Member

@cretz cretz May 15, 2025

Choose a reason for hiding this comment

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

serviceerror package should NOT be in this repo at all. This is a mistake I made long time ago.

But it's used in the SDK and by users, what repo should it be in? Also, you have the ability to add these helpers in whatever repo you think, there's no requirement to add them in this one, so you don't have to perpetuate your mistake.

Go SDK has several instances of serviceerror.New(fmt.Sprintf(...)), it can and should also use these new constructors.

Right, I am not questioning the validity of the methods, I am questioning the user-facing aspect. These types of things are added in the Go SDK because we expect users to use them and therefore we are ok with the increased API surface area, stability guarantees, etc.

Also, it would be pretty weird to have the NewSomething constructor be in this package but the NewSomethingf constructor be in a whole other package.

I assume you mean weird to server developers, because it is not weird to everyone else that uses this library to not have those server-only helpers. We have to always keep users in mind, not just ourselves. It is very important.

My primary concern is adding server-only helpers to this repository. It is less of a concern with these of course since they are simple constructor overloads. But in general it's a bad pattern to add "server-developer-only helpers" to this user-facing library.

If y'all feel strongly enough about giving all users these helpers, ok (let me know via response), but we would prefer server-only code to be server-only code as a general rule (of course just some overloaded constructors is not that big of a deal).

Copy link
Contributor

Choose a reason for hiding this comment

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

They are not server-only. And yes, they should be here with the non-f constructors.

Copy link
Member

@cretz cretz May 15, 2025

Choose a reason for hiding this comment

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

They are not server-only

This is at odds with some of the other comments, e.g. "It is not used by SDK. Only by server", hence the concern/thread here. Marking approved though I do think it's important to keep in mind that we should not clutter user packages with server-only needs if we can help it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not used by SDK yet 🙂

return &AlreadyExists{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *AlreadyExists) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/canceled.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -20,6 +22,13 @@ func NewCanceled(message string) error {
}
}

// NewCanceledf returns new Canceled error with formatted message.
func NewCanceledf(format string, args ...any) error {
return &Canceled{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *Canceled) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/cancellation_already_requested.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

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

Expand All @@ -22,6 +24,13 @@ func NewCancellationAlreadyRequested(message string) error {
}
}

// NewCancellationAlreadyRequestedf returns new CancellationAlreadyRequested error with formatted message.
func NewCancellationAlreadyRequestedf(format string, args ...any) error {
return &CancellationAlreadyRequested{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *CancellationAlreadyRequested) Error() string {
return e.Message
Expand Down
10 changes: 10 additions & 0 deletions serviceerror/client_version_not_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func NewClientVersionNotSupported(clientVersion, clientName, supportedVersions s
}
}

// NewClientVersionNotSupportedf returns new ClientVersionNotSupported error with formatted message.
func NewClientVersionNotSupportedf(clientVersion, clientName, supportedVersions, format string, args ...any) error {
return &ClientVersionNotSupported{
Message: fmt.Sprintf(format, args...),
ClientVersion: clientVersion,
ClientName: clientName,
SupportedVersions: supportedVersions,
}
}

// Error returns string message.
func (e *ClientVersionNotSupported) Error() string {
return e.Message
Expand Down
2 changes: 1 addition & 1 deletion serviceerror/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func FromStatus(st *status.Status) error {
return st.Err()
}

func extractErrorDetails(st *status.Status) interface{} {
func extractErrorDetails(st *status.Status) any {
details := st.Details()
if len(details) > 0 {
return details[0]
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/data_loss.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -20,6 +22,13 @@ func NewDataLoss(message string) error {
}
}

// NewDataLossf returns new DataLoss error with formatted message.
func NewDataLossf(format string, args ...any) error {
return &DataLoss{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *DataLoss) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/deadline_exceeded.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -20,6 +22,13 @@ func NewDeadlineExceeded(message string) error {
}
}

// NewDeadlineExceededf returns new DeadlineExceeded error with formatted message.
func NewDeadlineExceededf(format string, args ...any) error {
return &DeadlineExceeded{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *DeadlineExceeded) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/failed_precondition.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -20,6 +22,13 @@ func NewFailedPrecondition(message string) error {
}
}

// NewFailedPreconditionf returns new FailedPrecondition error with formatted message.
func NewFailedPreconditionf(format string, args ...any) error {
return &FailedPrecondition{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *FailedPrecondition) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/internal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -20,6 +22,13 @@ func NewInternal(message string) error {
}
}

// NewInternalf returns new Internal error with formatted message.
func NewInternalf(format string, args ...any) error {
return &Internal{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *Internal) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/invalid_argument.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -20,6 +22,13 @@ func NewInvalidArgument(message string) error {
}
}

// NewInvalidArgumentf returns new InvalidArgument error with formatted message.
func NewInvalidArgumentf(format string, args ...any) error {
return &InvalidArgument{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *InvalidArgument) Error() string {
return e.Message
Expand Down
6 changes: 6 additions & 0 deletions serviceerror/multi_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package serviceerror

import (
"errors"
"fmt"

"go.temporal.io/api/errordetails/v1"
"google.golang.org/grpc/codes"
Expand All @@ -20,6 +21,11 @@ func NewMultiOperationExecution(message string, errs []error) error {
return &MultiOperationExecution{Message: message, errs: errs}
}

// NewMultiOperationExecutionf returns a new MultiOperationExecution error with formatted message.
func NewMultiOperationExecutionf(errs []error, format string, args ...any) error {
return &MultiOperationExecution{Message: fmt.Sprintf(format, args...), errs: errs}
}

// Error returns string message.
func (e *MultiOperationExecution) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/multi_op_aborted.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

failurepb "go.temporal.io/api/failure/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -19,6 +21,13 @@ func NewMultiOperationAborted(message string) error {
}
}

// NewMultiOperationAbortedf returns MultiOperationAborted with formatted message.
func NewMultiOperationAbortedf(format string, args ...any) error {
return &MultiOperationAborted{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e MultiOperationAborted) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/namespace_already_exists.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

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

Expand All @@ -22,6 +24,13 @@ func NewNamespaceAlreadyExists(message string) error {
}
}

// NewNamespaceAlreadyExistsf returns new NamespaceAlreadyExists error with formatted message.
func NewNamespaceAlreadyExistsf(format string, args ...any) error {
return &NamespaceAlreadyExists{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *NamespaceAlreadyExists) Error() string {
return e.Message
Expand Down
9 changes: 9 additions & 0 deletions serviceerror/not_found.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

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

Expand All @@ -24,6 +26,13 @@ func NewNotFound(message string) error {
}
}

// NewNotFoundf returns new NotFound error with formatted message.
func NewNotFoundf(format string, args ...any) error {
return &NotFound{
Message: fmt.Sprintf(format, args...),
}
}

// Error returns string message.
func (e *NotFound) Error() string {
return e.Message
Expand Down
10 changes: 10 additions & 0 deletions serviceerror/permission_denied.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

"go.temporal.io/api/errordetails/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -23,6 +25,14 @@ func NewPermissionDenied(message, reason string) error {
}
}

// NewPermissionDeniedf returns new PermissionDenied error with formatted message.
func NewPermissionDeniedf(reason, format string, args ...any) error {
return &PermissionDenied{
Message: fmt.Sprintf(format, args...),
Reason: reason,
}
}

// Error returns string message.
func (e *PermissionDenied) Error() string {
return e.Message
Expand Down
20 changes: 18 additions & 2 deletions serviceerror/query_failed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package serviceerror

import (
"fmt"

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

Expand All @@ -12,8 +14,7 @@ type (
// QueryFailed represents query failed error.
QueryFailed struct {
Message string
// The full reason for this query failure. May not be available if the response is generated by an old
// SDK.
// The full reason for this query failure. May not be available if the response is generated by an old SDK.
Failure *failure.Failure
st *status.Status
}
Expand All @@ -26,6 +27,13 @@ func NewQueryFailed(message string) error {
}
}

// NewQueryFailedf returns new QueryFailed error with formatted message.
func NewQueryFailedf(format string, args ...any) error {
return &QueryFailed{
Message: fmt.Sprintf(format, args...),
}
}

// NewQueryFailed returns new QueryFailed error.
func NewQueryFailedWithFailure(message string, failure *failure.Failure) error {
return &QueryFailed{
Expand All @@ -34,6 +42,14 @@ func NewQueryFailedWithFailure(message string, failure *failure.Failure) error {
}
}

// NewQueryFailedWithFailuref returns new QueryFailed error with failure and formatted message.
func NewQueryFailedWithFailuref(failure *failure.Failure, format string, args ...any) error {
return &QueryFailed{
Message: fmt.Sprintf(format, args...),
Failure: failure,
}
}

// Error returns string message.
func (e *QueryFailed) Error() string {
return e.Message
Expand Down
Loading